Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I have a specific fancybox.js file which I want to load at the end of all the JS files included in my local.xml

If load order can be changed then how can a JS file be loaded (included) at the end ?

Thanks.

share|improve this question

2 Answers 2

You can sort the order of skin or js files in layout.xml by using the params element with a name attribute like this answer explains:-

<action method="addJs"><!-- this will be shown second -->
    <script>prototype/javascript1.js</script>
    <params><![CDATA[name="js002_second"]]></params>
</action>
<action method="addJs"><!-- this will be shown first -->
    <script>prototype/javascript2.js</script>
    <params><![CDATA[name="js001_first"]]></params>
</action>
share|improve this answer
    
Nice...I learn something new everyday. –  Marius Apr 4 at 11:13
    
If i have only one JS to be included at the end of all JS files then how the above method will work ? –  Mark Apr 4 at 12:55
    
Try <params><![CDATA[name="zjs_last"]]></params> and see what happens (I'm not 100% certain). Report back if that doesn't load it after all others. –  zigojacko Apr 4 at 12:56
    
No its not working somehow..:( –  Mark Apr 5 at 4:11
    
@Mark - Hmm, okay, I'm guessing each js call will require a params element with name attribute or you could try modifying so that you can include a sort order or is it not possible to just place the fancybox js call after all others? –  zigojacko Apr 7 at 7:10

I don't think you can specify a sort order for the js files you add (apparently you can see answer provided by @zigojacko), but I think you can do it a bit differently, buy adding a child block to the head block.
All the children of the head block are rendered after the js and css elements.

Here is what you need.

Add this to one of your layout files.

<reference name="head">
    <block type="core/template" name="fancy" as="fancy" template="fancybox/fancybox.phtml" />
</reference>

Then create the file app/design/frontend/{package}/{theme}/template/fancybox/fancybox.phtml with the following content.

<script type="text/javascript" src="<?php echo Mage::getBaseUrl('js').'/fancybox.js'?>"></script>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.