Last Updated: July 27, 2016
·
759
· moak

Zend_View_Helper_FootScript

We know it's good practice to include JavaScript files at the bottom of the page, and the HeadScript helper is pretty useful for managing all your view's java scripts calls and files, however there are cases where you want to load scripts in the header (prefixfree, html5 shiv, etc..) and the remaining ones in the bottom of your layout. Simply extending the HeadScript helper won't do, you will need to change the registry key and the default function call.

FootScript.php

<?php
class Zend_View_Helper_FootScript extends  Zend_View_Helper_HeadScript{
    /**
     * Registry key for placeholder
     * @var string
     */
    protected $_regKey = 'Zend_View_Helper_FootScript';
    /**
     * Return footScript object
     *
     * Returns footScript helper object; optionally, allows specifying a script
     * or script file to include.
     *
     * @param  string $mode Script or file
     * @param  string $spec Script/url
     * @param  string $placement Append, prepend, or set
     * @param  array $attrs Array of script attributes
     * @param  string $type Script type and/or array of script attributes
     * @return Zend_View_Helper_FootScript
     */
    public function footScript($mode = Zend_View_Helper_HeadScript::FILE, $spec = null, $placement = 'APPEND', array $attrs = array(), $type = 'text/javascript'){
        return $this->headScript($mode,$spec,$placement,$attrs,$type);
    }
}

Example layout.phtml

<?php echo $this->doctype(); ?>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <?php echo $this->headMeta().$this->headTitle().$this->headStyle().$this->headLink().$this->headScript();?>
    </head>
    <body>
        <?php echo $this->layout()->content; ?>
        <?php echo $this->footScript();?>
    </body>
</html>