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

MeenakshiSundaram R
  • 9,577
  • 7
  • 33
  • 56
konika
  • 579
  • 2
  • 7
  • 23

2 Answers2

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

MeenakshiSundaram R
  • 9,577
  • 7
  • 33
  • 56
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.

mkutyba
  • 460
  • 5
  • 22