4

I want to add js in my custom module layout xml file Below is my code:

<reference name="head">
   <action method="addJs"><script>varien/provfvfvfvf.js</script></action>
</reference>

I have added js but I wont be able to see this js in my module pages. Whats the thing which I m missing please let me know

  • <reference name="head"> <action method="addJs"><script>varien/provfvfvfvf.js</script></action></reference> this is my code which I m using – konika Aug 17 '15 at 8:37
  • check the cache and clear it – saravanavelu Aug 17 '15 at 8:38
  • where provfvfvfvf.js this file is their in your folder structure – Pradeep Sanku Aug 17 '15 at 8:39
  • it should be under js/varien/provfvfvfvf.js then it will work fine – Pradeep Sanku Aug 17 '15 at 8:40
  • my file path is /skin/frontend/tm_themes/theme724/js/lib/elevatezoom/jquery.elevateZoom-3.0.8.min.js – konika Aug 17 '15 at 8:42
3

You have specify the Handle. If you want to add the js files for all page use default handle. i.e.,

<default>
    <reference name="head">
        <action method="addJs"><script>varien/provfvfvfvf.js</script></action>
    </reference>
</default>

Or else you want to add only one page

[router_config_node_name]_[controller_name]_[action_name]

router_config_node

eg:

<catalog_product_view>

Refer this Link

1

I use this snippet:

<action method="addItem"><type>skin_js</type><name>js/script.js</name></action>

EDIT:

Add layout update in module's config app/code/.../Your/Module/etc/config.xml

<frontend>
    <layout>
        <updates>
            <your_module>
                <file>your_module.xml</file>
            </your_module>
        </updates>
    </layout>
</frontend>

Put it in layout update file app/design/frontend/base/default/layout/your_module.xml

<default>
    <reference name="head">
        <action method="addItem"><type>skin_js</type><name>js/script.js</name></action>
    </reference>
</default>

I used handle default but you can use any other handle, according to your needs, e.g. yourmodule_controller_action.

Your js file should be in skin/frontend/base/default/js/script.js.

  • under which tag you used it? – konika Aug 17 '15 at 8:51
  • <reference name="head"> You can place your js file in skin/frontend/base/default/... – mkutyba Aug 17 '15 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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