views:

67

answers:

2

Hi,

I'm using Zend_view/Zend_Layout but i want to be able to append scripts to the overall template depending on the controller, so within the controller i could do something like:

public function someAction()
{
    $something->headScript()->appendFile('script.js','text/javascript');
    // etc etc
}

I have enabled Zend_view/Zend_Layout like this:

in application.ini:

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"

and in Bootstrap.php:

protected function _initView()
{
    $view = new Zend_View();
    $view->doctype('XHTML1_STRICT');
    $view->headTitle('zend layout tester');
    // Add it to the ViewRenderer
    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
        'ViewRenderer'
    );
    $viewRenderer->setView($view); 
    // Return it, so that it can be stored by the bootstrap
    return $view;
}
+2  A: 

Does this work?

public function someAction()
{
    $this->view->headScript()->appendFile('script.js','text/javascript');
    // etc etc
}
Gordon
haha, indeed it does. thanks!
seengee
+1  A: 

Put in layout template

{headScript()}

And in controller's action:

$this->view->headScript()->appendFile('path/to/script.js');
hsz