Kir*_*kov 0 html css layout twitter-bootstrap yii2
在Yii2中为页面制作不同布局的最佳做法是什么?我面临的问题是Yii2 layout/main.php代码看起来像
<div class="container">
<?= $content ?>
</div>
Run Code Online (Sandbox Code Playgroud)
Yii2使用Bootstrap,我只需要在site/index.php中制作全宽图像.基本上在index.php中我需要换行
<?= $this->render('_search') ?>
Run Code Online (Sandbox Code Playgroud)
进入.container-fluid类.
如何才能将.container类替换为.container-fluid类仅用于index.php页面?
制作一个新的布局,例如layout-fluid.php,在控制器中
public function actionIndex()
{
$this->layout = 'layout-fluid';
return $this->render('index');
}
Run Code Online (Sandbox Code Playgroud)
如果流体容器是您需要的唯一更改,则可以执行此操作:在索引视图文件中添加
$this->params['fluid'] = true;
Run Code Online (Sandbox Code Playgroud)
并在布局文件中将所需的容器更改为
<div class="container<?= $this->params['fluid'] ? '-fluid' : '' ?>">
Run Code Online (Sandbox Code Playgroud)
params 数组是在视图中传播信息的好地方.
| 归档时间: |
|
| 查看次数: |
2412 次 |
| 最近记录: |