简体   繁体   English

向Magento添加JavaScript代码段

[英]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. 我正在尝试向每个网站的朋友网站添加JavaScript。 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) (他不是Magento Go的人吗?他是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. 因此,我询问了他的FTP详细信息,以便可以编辑模板中的.phtml文件,但是他的FTP上没有Magneto文件结构。 However when you go to his site you can do "/skin/frontend" and the folders are present. 但是,当您访问他的站点时,您可以执行“ / skin / frontend”并且文件夹存在。

Could there be other FTP details, or levels of access that perhaps his website designers used? 可能还有其他FTP详细信息,或者他的网站设计师可能使用的访问级别?

Instead of modifying .phtml file you have to add javascript via XML layout. 无需修改.phtml文件,您必须通过XML布局添加javascript。 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. 为此,登录Magento管理界面,转到System \\ Configuration \\ Design,然后分别检查第一个和第二个选项的“包”和“默认”值。
  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. 将JS文件上传到skin/frontend/PACKAGE_NAME/THEME_NAME/js ,其中PACKAGE_NAME是您在步骤1的“打包”字段中找到的值,而THEME_NAME是您在“默认”字段中找到的值。
  3. Go to app/design/frontend/PACKAGE_NAME/THEME_NAME/layout and create a local.xml file with the following content: 转到app/design/frontend/PACKAGE_NAME/THEME_NAME/layout并创建具有以下内容的local.xml文件:

     <?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). 别忘了清除Magneto缓存(Admin \\ System \\ Cache Management)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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