Magento – AddJs / CSS in footer. getCssJsHtml() not working

cssfooterjavascript

I've been looking through a lot of posts on how to add CSS / JS file in the footer.

As right now I have followed this path : page.xml

<block type="page/html_head" name="foot" as="foot" template="page/html/foot.phtml"/>

local.xml
I did try all the variant, type/skin_js, addJs, addItem

<reference name="foot">
    <action method="addJs"><script>lebernard/test.js</script></action>
</reference>

foot.phtml
Translator script is rendering as normal, so foot.phtml is getting called. I tested it with a string as well.

<?php echo $this->getCssJsHtml() ?>
<?php echo $this->getChildHtml() ?>
<?php echo $this->helper('core/js')->getTranslatorScript() ?>
<?php echo $this->getIncludes() ?>

Finally I'm calling in 1column.phtml (and others) getChildHtml('foot');

So I though it was a misplaced JavaScript file since the translator script is called properly. I did put it as follow in :

  • /js/lebernard/test.js
  • /js/test.js
  • /skin/[theme]/js/test.js

All I want is to include a js file in the footer using local.xml . I'm on 1.9.0.1.

Best Answer

If all you are trying to do is add a JS file inclusion in the footer, the easiest way might be to just put it in a template file. So in your local.xml file.

<default>
    <reference name="footer">
        <block type="core/template" template="my-template-file.phtml"/>
    </reference>
</default>

And then in my-template-file.phtml:

<script type="text/javascript" src="<?php $this->getSkinUrl('js/my-js-file.js'); ?>"></script>
Related Topic