Reputation: 23100
Is there a out of the box way of loading certain javascripts in the footer of a view script?
This would be particularly useful for such scripts like google analytics, etc.
Or would this require extending $this->headScript() and creating a $this->footScript() ?
Upvotes: 2
Views: 2906
Reputation: 8519
use a placeholder in your layout like $this->layout()->footScript
and then attach the code you want to the placeholder.
Or you could just use the inlineScript() Helper. The inlineScript helper has the same api is headScript().
The optimum would probably be to use the layout placeholder along with the inlineScript helper.
An Example of the inlineScript helper:
//I use this in some of my controllers, in the predispatch()
$this->view->inlineScript()->setScript(
"$('audio').mediaelementplayer();");
//then I just attach this to any view (including layout)
<?php echo $this->inlineScript() ?>
Use something like this with a placeholder and you have javascript anywhere.
Upvotes: 6
Reputation: 7341
Using PHP, putting auto_append_file
in a php.ini
file or .htaccess
file may be what you are looking for.
Link: php.net/manual/en/ini.core.php#ini.auto-append-file
If you don't have access to php.ini
you can put
php_value auto_append_file "file_to_append.php"
into an .htaccess
file.
Keep in mind, however, that this will append it after the closing HTML tags, and therefore invalidate the markup.
I only use this for PHP scripts that don't output anything.
Upvotes: 0