Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How do I add javascript to head with access to template methods? 
 
JazzcatCB
Jr. Member
 
Total Posts:  24
Joined:  2008-02-06
 

I need to add some js to the head section. I also need to access relative paths in this js. The code looks like this:

<head>
. . .
<
script type="text/javascript">
var 
flashvars {};
var 
params {};
var 
attributes {};
attributes.id "faculty-flash";
swfobject.embedSWF("faculty_sidebar.swf""myAlternativeContent""191""320""9.0.0"falseflashvarsparamsattributes);
</script>
. . .
</
head>

faculty_sidebar.swf is located in the skin directory, so I need to supply the relative path to this file. Can anyone help me out? Thanks in advance.

 
Magento Community Magento Community
Magento Community
Magento Community
 
iblastoff
Sr. Member
 
Total Posts:  252
Joined:  2007-08-31
 

many ways to do this. if you place that js in an actual file within your theme/js directory then you can probably call it via page.xml with

<action method="addItem"><type>skinJs</type><name>filename.js</name></action>

or you could place it directly within head.phtml and to supply the url, you could use

<script type="text/javascript">
...
swfobject.embedSWF("<?=$this->getSkinUrl('flash/faculty_sidebar.swf')?>""myAlternativeContent""191""320""9.0.0"falseflashvarsparamsattributes);
...
</script>

(assuming you created a /flash directory within /skin/your_interface/your_theme/)

 
Magento Community Magento Community
Magento Community
Magento Community
 
JazzcatCB
Jr. Member
 
Total Posts:  24
Joined:  2008-02-06
 

Thank you iblastoff. That helped a lot.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top