Flexer
Flexer

Reputation: 131

Load phtml content in custom viewhelper?

In my main layout.phtml i've included a custom viewhelper. The viewhelper has lot of static html content and returns it to the layout.

Is there a way that the viewhelper loads this html content from an external phtml file?

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>

Upvotes: 1

Views: 727

Answers (1)

b.b3rn4rd
b.b3rn4rd

Reputation: 8830

public function viewHelperGiveMeHtml(){
    $this->view->render('foobar.phtml');
}   

Brief explanation:

When you're calling view helper $this->viewHelperGiveMeHtml(); inside view, Zend_View initialise given helper class and passes itself using Zend_View_Helper_Abstract::setView method.

Upvotes: 1

Related Questions