xelurg
xelurg

Reputation: 4304

Dynamically include .js files from Zend_Controller_Action?

I came across the case where depending on the execution path I may need to invoke an inclusion of .js file from controller. Is there a nice way of doing it? (besides setting some view variable with actual .js include code)?

Upvotes: 4

Views: 5828

Answers (2)

smack0007
smack0007

Reputation: 11366

See the view helper headScript(). I'm just writing this off the top of my head but I think it works like this:

From within a view file: $this->headScript()->appendFile('filename.js');

From within a controller: $this->view->headScript()->appendFile('filename.js');

And then somewhere in your layout you need to echo out your headScript object:

<?=$this->headScript();?>

Upvotes: 8

martinsb
martinsb

Reputation: 945

Sure, you could do like @Bill Karwin described.

But if you would like to do it really nicely, you need template inheritance - like it is implemented in Django framework for Python for instance. There are some extensions for Zend Framework as well, take a look at Calypso.

Upvotes: 0

Related Questions