简体   繁体   中英

Adding a JavaScript Snippet to Magento

I'm trying to add a piece of JavaScript to a friends website which needs to be on every page. However looking on the backend of his site there is no were to add/edit the template he is using. (He isnt on Magento Go? He's on version 1.5)

So I asked him for his FTP details so I could edit the .phtml files in the template however there is no Magneto file structure on his FTP. However when you go to his site you can do "/skin/frontend" and the folders are present.

Could there be other FTP details, or levels of access that perhaps his website designers used?

Instead of modifying .phtml file you have to add javascript via XML layout. Here how you do it:

  1. You need to locate the which directories to use. To do so log into Magento admin interface, go to System\\Configuration\\Design and Check "Package" and "Default" values of 1st and 2nd options grops correspondently.
  2. Upload the JS file into skin/frontend/PACKAGE_NAME/THEME_NAME/js where PACKAGE_NAME is the value you found in "Package" field in step 1 and THEME_NAME is the value you found in "Default" field.
  3. Go to app/design/frontend/PACKAGE_NAME/THEME_NAME/layout and create a local.xml file with the following content:

     <?xml version="1.0."?> <layout version="0.1.0"> <cms_page> <reference name="head"> <action method="addJs"><stylesheet>js/YOUR_SCRIPT.js</stylesheet></action> </reference> </cms_page> </layout> 

That's all. Don't forget to clear Magneto caches after all (Admin\\System\\Cache Management).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM