Load js in footer in Magento
The footer doesn't have these functionalities, only the head
does as this block is of type page/html_head
which holds these methods.
You can achieve this by putting the JS <script src=...></script>
tag inside a template (.phtml
file) and include that as a core/template
block:
<reference name="footer">
<block type="core/template" name="fabric_controller_tool_js" template="fabric/controller_tool_js.phtml" />
</reference>
Also you could add it through a core/text
block:
<reference name="footer">
<block type="core/text" name="fabric_controller_tool_js">
<action method="setText">
<text><![CDATA[<script src="/js/fabric/tool/controller_tool.js"></script>]]></text>
</action>
</block>
</reference>
Currently Magento footer block has not been designed to add javascripts.
I tried a while ago refactoring Magento and the footer block to load every JS in the footer instead of the header but the way the JS call are called inside the templates makes it very hard to get this working.
My suggestion to fix your issue is to update your layout like this:
<reference name="before_body_end">
<block type="core/template" name="controller_tool_javascript" template="fabric/tool/controller_tool_js.phtml"/>
</reference>
Create a fabric/tool/controller_tool_js.phtml
file in your template folder with the following code:
<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/fabric/tool/controller_tool.js') ?>"></script>
Let me know if that works.
Just want tell you why addItem
not work in reference name="footer"
When you use reference name="footer"
then it will call this block
<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
which you will find in page.xml
in your theme.
so it mean it will check addItem
method/function in that block class or in their parent class, but this function is not there, that's why it will not work and it will throw exception.