Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create layout that use header and footer partials

I have red the guide about views and layouts, I have googled how to to this, but I still can not make it work. Here is the problem:

I want to have 2column.php and 3column.php layouts, where both are using _header.php and _footer.php partials.

2columns.php layout example:

render _header.php

$content and some other extra code

render _footer.php

Whatever I do I can not make it work. Can someone please post me real simple example of how to achieve this ? Thanks

Please note that answer:

use:

<?php $this->beginContent('@app/views/layouts/header.php'); ?>
    <!-- You may need to put some content here -->
<?php $this->endContent(); ?>

does not help me... don't know what to do with it, I cant make it do what I need.

like image 683
offline Avatar asked Jun 02 '15 09:06

offline


People also ask

What is partial design?

Partial designs are a unique or particular portion of a full product design. Often, they are part of a product that cannot be separated, sold, or used independently.


1 Answers

You should simply try :

<?php $this->beginPage() ?>
<?= $this->render('@app/views/layouts/header', $_params_) ?>

<!-- main content -->

<?= $this->render('@app/views/layouts/footer', $_params_) ?>
<?php $this->endPage() ?>

And don't forget to use the following in your header view :

<head>
    <?= Html::csrfMetaTags() ?>
    <?php $this->head() ?>
    ...
</head>

Read more :

  • About render() : http://www.yiiframework.com/doc-2.0/yii-base-view.html#render()-detail
  • About layouts : http://www.yiiframework.com/doc-2.0/guide-structure-views.html#layouts
like image 159
soju Avatar answered Sep 28 '22 10:09

soju