Magento module layout xml order

1.9k views Asked by At

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?

1

There are 1 answers

2
benmarks On BEST ANSWER

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 the head block and use a template with theme-safe links to your JS files or add a core/text block and call setText() with explicit links to your JS files (less secure, generally used for CDN-hosted scripts). There is an empty getChildHtml() call in page/html/head.phtml which will render any child blocks of head.