2011-10-20 48 views
1

我想在zend框架中實現模板系統。使用Zend_Layout管理多個佈局?

我基本上用來把所有partials文件和模板的變化放在一個文件中,但隨着模板的增加,這是非常難以管理的。

例如

/application/layout/script/template1partial-banner.phtml 
/application/layout/script/template1partial-footer.phtml 
/application/layout/script/template1variation1.phtml 
/application/layout/script/template1variation2.phtml 
/application/layout/script/template2variation1.phtml 
/application/layout/script/template2variation2.phtml 

可以看到,如何難以管理,這是 ,所以我想在此結構之下進行管理

/application/layout/script/template1/partial/banner.phtml 
/application/layout/script/template1/partial/footer.phtml 
/application/layout/script/template1/variation/1.phtml 
/application/layout/script/template1/variation/2.phtml 

/application/layout/script/template2/partial/banner.phtml 
/application/layout/script/template2/partial/footer.phtml 
/application/layout/script/template2/variation/1.phtml 
/application/layout/script/template2/variation/2.phtml 

好界定諧音是沒有問題的,你可以使用$this -> render($this -> getTemplateName()."/partials/banner.phtml");

它的變化,這是主要問題 我用$this -> _helper -> layout -> setLayout('template1variation1');之前,但現在,我不能使用它的新事物。

我該怎麼做這件事?

回答

2

您還可以在您的layout函數中定義完整路徑。做這個任務

$this->_helper->layout->setLayout('template1/partial/banner'); 

的另一種方式是針對當前的行動禁用佈局,然後使它對任何PHTML文件。例如第一disable佈局當前操作

$this->_helper->layout->disableLayout(); 

然後就渲染這樣

 $this->render("complete path to your phmtl file"); 
任何HTML文件