I'm using a custom module in my Magento installation, which uses a layout XML file to add some Javascript files into the head section of every page.
This works fine, however these javascript files need to be added AFTER the ones I've already declared in page.xml, however it would seem the XML files are processed alphabetically as opposed to hierarchically!
I've looked through the page/html_head block and there seems to be no native way to set/change the order in which items are included. Without removing the javascript files from my module's XML file and placing them in page.xml, does anyone have any idea how I could ensure the page.xml javascript is added first?
Layout XML files are processed alphabetically only as an effect of module load order, which is subject to the alphabetical ordering of
glob()
.While the missing sort functionality for the head block is unfortunate, there is a workaround. You can make your module dependent on
Mage_Page
in your module activation file.Other options are: add a
core/template
block to thehead
block and use a template with theme-safe links to your JS files or add acore/text
block and callsetText()
with explicit links to your JS files (less secure, generally used for CDN-hosted scripts). There is an emptygetChildHtml()
call inpage/html/head.phtml
which will render any child blocks ofhead
.