I'm trying to add a javascript to all Magento pages inside tag <head>
. I have a file called example.xml
in this folders tree (I've made a configuration on etc/config.xml
to use a custom .xml file like example.xml
):
--design
----frontend
------base
--------default
----------layout
------------example.xml
I'm using two approaches to do this. The first one is (NOT WORKING):
<layout>
<default>
<reference name="head">
<action method="addJs">
<script>folder/myjavascript.js</script>
</action>
</reference>
</default>
</layout>
The second one is (WORKING only for checkout page):
<layout>
<example_handle>
<reference name="head">
<action method="addJs">
<script>folder/myjavascript.js</script>
</action>
</reference>
</example_handle>
<checkout_onepage_index>
<update handle="example_handle"/>
</checkout_onepage_index>
<onepagecheckout_index_index>
<update handle="example_handle"/>
</onepagecheckout_index_index>
<opc_index_index>
<update handle="example_handle"/>
</opc_index_index>
<aw_onestepcheckout_index_index>
<update handle="example_handle"/>
</aw_onestepcheckout_index_index>
</layout>
My javascript has a snippet where I need to get a custom variable from Magento (in php I use getConfigData('api_key')
). So, my second question is: Is it possible to get this value directly from javascript or I need to do this with php?
var _api_key = ?`getConfigData('api_key')`?;