JavaScript (and images, CSS, flash movies, etc.) belong to the presentation layer, so customize them there.
For files with global inclusion, add them to the layout, for example
<head> <?php echo $this->headScript()->prependFile( $this->baseUrl('path/to/file.js')) ?> <?php echo $this->headLink()->prependStylesheet( $this->baseUrl('path/to/file.css')) ?> <?php echo $this->inlineScript()->prependFile( 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js') ?> </body>
Your view scripts can then add assets to assistants, which are reflected in the layout. Since the layout uses prepend*()
methods, global files will be displayed first, for example
<?php // views/scripts/index/index.phtml $this->inlineScript()->appendFile($this->baseUrl('path/to/script.js'));
source share