Using the headScript helper is much easier. Use $this->headScript()->appendFile('filenameandpath.js')
then in your header use <?php echo $this->headScript(); ?>
The only thing is that you need to call appendScript before you call echo. If you are using Zend_Layout, $this->layout()->content is called first, so if you append your script in there, and then echo it any where in your layout you will be fine.
For example:
In your controller have
$this->view->headScript()->appendFile('http://www.site.com/js/event.js');
then in your header.phtml file have
<?php echo $this->headScript(); ?>
Btw, there are also headTitle, headLink, headMeta, and headStyle. All very helpful.
Regards,
Adam
On Aug 21, 2008, at 8:57 AM, Jigal sanders wrote:
Hello everyone.
In my view scripts i do
<?php echo $this->render('header.phtml'); ?>
<?php echo $this->render('menu.phtml'); ?>
then page specifics
<?php echo $this->render('footer.phtml'); ?>
Now in my header.phtml i have something like:
<?php if ($this->script){?>
<script type="text/javascript" src="http://www.site.com/js/.<?$this->script?>."></script>
<?php } ?>
But when i say in my controller:
$this->script = "event.js";
then it doesn't work.
My question is: how can I set the variable $this->script in my header template from within my controller?
Thanks in advance,
J.Sanders
没有评论:
发表评论