-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Comments
I have met this question too, but i cant get the solution method |
ok, use case - in your view/layouts folder you make a new column2.php <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"; |
Thanks, we are trying it now! |
And I forgott, the blocks can be used as dynamic placeholder... I fill them late using :) |
What is block? Is it a widget? |
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(); ?> |
Got it, Thanks! |
you are welcome! |
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.
The text was updated successfully, but these errors were encountered: