Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reuse main layout file, like the column1 & column2 in Yii1. #1626

Closed
qiansen1386 opened this issue Dec 26, 2013 · 8 comments
Closed

Comments

@qiansen1386
Copy link
Contributor

I am sorry to bother you guys.

We checked the both sections of the doc : view.md#layout and apps-basic.md#views

But we can't find how to reuse the main layout. We are wondering that is there still a way to do so, or Yii 2 has made several changes on this portion?

Currently we assume that the default layout logic is pretty simplified and beginner-friendly. If we want to have premium requirement we should use a template engine? Probably twig?

We are glad to hear more about the new design principles on Yii

Thank you for your attention and looking forward to your reply.

@yinhe
Copy link

yinhe commented Dec 26, 2013

I have met this question too, but i cant get the solution method

@philippfrenzel
Copy link
Contributor

ok, use case - in your view/layouts folder you make a new column2.php
this should look like this:

<php $this->beginContent('@app/views/layouts/main.php'); ?>

<div class="row">
   <div class="col-md-3">
    <div class="pg-sidebar">          
      <?= $this->blocks['sidebar']; ?>

      <?= $this->blocks['toolbar']; ?>
    </div>      
  </div>
  <div class="col-md-9">
    <?= $content; ?>
  </div>
</div>
<php $this->endContent(); ?>

And in your controller, you set a new public variable:

public $layout = "/main";

In your ControllerAction you can set layout by:

$this->layout = "/column2";

@qiansen1386
Copy link
Contributor Author

Thanks, we are trying it now!

@philippfrenzel
Copy link
Contributor

And I forgott, the blocks can be used as dynamic placeholder... I fill them late using
yii\widgets\Block;

:)

@qiansen1386
Copy link
Contributor Author

What is block? Is it a widget?

@philippfrenzel
Copy link
Contributor

yes, can be used like this:

<?php Block::begin(array('id'=>'sidebar')); ?>

    <?php

                echo SideNav::widget([
                'type' => SideNav::TYPE_DEFAULT,
                'heading' => Yii::t('app','Party Options'),
                'items' => 
                [
                    [
                        'url' => ['/site/index'],
                        'label' => 'Home',
                        'icon' => 'home'
                    ],
                    ['label' => Yii::t('app','Create'), 'icon'=>'plus', 'url'=>['create']]
                  ]
        ]);
   ?>   
<?php Block::end(); ?>

@qiansen1386
Copy link
Contributor Author

Got it, Thanks!

@philippfrenzel
Copy link
Contributor

you are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants