Reputation: 2721
I'm reading the manual here: http://zendframework.com/manual/en/zend.view.helpers.html
but I'm still confused. I have a script in my head that I'm converting to the layout/view for the Zend MVC:
<script type="text/javascript">
var embedCode = '<object data="http://example.com" type="application/x-shockwave-flash" height="385" width="475"><param name="src" value="http://example.com" /><param name="allowfullscreen" value="true" /></object>'
</script>
I first tried to add it is an external file like this (in layout):
$this->headScript()->appendFile('js/embeddedVideo.js')->appendScript($onloadScript);
<head>
<?php echo $this->headScript(); ?>
</head>
Didn't really work, but anyway, I'm wanting to just add the script and not add it as an external file. How do I do that?
Thanks!
Upvotes: 1
Views: 2939
Reputation: 50638
If you are using jQuery, for onload events use jQuery helper:
$this->view->jQuery()->addOnload($onloadScript);
In the layout script:
<?= $this->getPluginLoader('helper')->isLoaded("JQuery") ? $this->JQuery() . "\n" : "" ?>
Notice that ArneRie pointed out: there are already separate view helpers for specific tasks.
Upvotes: 1
Reputation: 20726
it's flash right? There a View Helpers wich are designed to put
Code on your website.
<?php echo $this->htmlFlash('/flash.swf'); ?>
You can read about this at the ZF Documentation for View Helpers ZF View Helper
Upvotes: 1
Reputation: 9072
If it was specific on the module, controller, action or something else, you could then consider using the headScript() helper. But if it's to be in every view, just put it directly in the layout head. No need to complicate it.
Upvotes: 0