[英]Load phtml content in custom viewhelper?
In my main layout.phtml i've included a custom viewhelper. 在我的主要layout.phtml文件中,我包含了一个自定义的viewhelper。 The viewhelper has lot of static html content and returns it to the layout. viewhelper具有大量静态html内容,并将其返回到布局。
Is there a way that the viewhelper loads this html content from an external phtml file? 有没有一种方法可以使viewhelper从外部phtml文件加载此html内容?
Abstract example: 抽象示例:
Layout:
<?php echo $this->viewHelperGiveMeHtml(); ?> //<div>Foobar</div>
ViewHelper:
class Zend_View_Helper_ViewHelperGiveMeHtml extends Zend_View_Helper_Abstract{
public function viewHelperGiveMeHtml(){
return retrieveHtmlFromPhtml('foobar.phtml'); //how can i load an phtml? file
}
}
foobar.phtml:
<div>Foobar</div>
public function viewHelperGiveMeHtml(){
$this->view->render('foobar.phtml');
}
Brief explanation: 简要说明:
When you're calling view helper $this->viewHelperGiveMeHtml();
调用视图助手时, $this->viewHelperGiveMeHtml();
inside view, Zend_View
initialise given helper class and passes itself using Zend_View_Helper_Abstract::setView
method. 在内部视图中, Zend_View
初始化给定的帮助器类,并使用Zend_View_Helper_Abstract::setView
方法传递自身。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.