2017-07-26 15 views
0

我想定製這個引導程序模板。 我的模板是這樣的:如何在Yii2中自定義引導模板?

圖片1

enter image description here

其實,我把引導模板的HTML中views/layout/main.php。所以,模板將一直存在。但是,我想讓菜單在主頁上可以不同於我的模板上的菜單views/layout/main.php。我想讓菜單不同。它是這樣的: 如首頁的第一頁,模板是這樣的:

圖二 enter image description here

然後當我選擇的年份:2012,那麼頁面應該有這樣的:

圖三 enter image description here

正如你看到的,圖二和PIC 3之間的不同是在側邊欄中的 「菜單」。我想一直製作圖3中的菜單。所以,當我打開其他菜單時,模板保持一致。當我將源代碼放在views/layout/main.php中時,這將是可能的。但是,Pic 2呢?該頁面有不同的菜單。

這是我在views\layout\main.php模板代碼:

https://pastebin.com/Yd5nQ9Er

回答

1

創建不同pages.You下面可以使用佈局的具體行動和控制器不同的佈局:

如果你想對控制器中的所有操作使用佈局,

class SiteController extends Controller //controller name 
{ 
    public $layout="main-template-1"; //layout name 
    // actions 
} 

如果您想要使用佈局行動比使用

public function actionIndex() // action name 
{ 
$this->layout = "main-template-1"; // layout 
} 
1

如果你想要改變作爲PIC1和PIC2看到你可以 得到URL本身的信息,如果條件對

views\layout\main.php 

而且創建菜單項如果你有不同的控制器,你可以得到控制器和動作ID

$controller = strtolower(Yii::$app->controller->id); 

$action = strtolower(Yii::$app->controller->action->id); 

然後根據你的動作和控制器,你可以顯示隱藏菜單

0

您可以使用動態塊:

<?php $this->beginBlock('block1'); ?> 
...content of block1... 
$this->endBlock(); ?> 

take a look