将自定义 Javascript 添加到 Prestashop
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34198378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add custom Javascript to Prestashop
提问by Cyssoo
After asking on the Prestashop forum and receiving no reply I wanted to ask you guys and hope for an answer.
在 Prestashop 论坛上询问并没有收到回复后,我想问你们并希望得到答案。
I am trying to add an animated snow plugin to my shop but after looking at the header.tpl file which instructs you to not edit - how do I add my own Javascript to the head of my template?
我正在尝试向我的商店添加一个动画雪插件,但在查看了指示您不要编辑的 header.tpl 文件后 - 如何将我自己的 Javascript 添加到我的模板的头部?
I duplicated the default-theme and I am working from that.
我复制了默认主题,我正在使用它。
回答by gskema
If the theme is default-bootstrap
, then yes, you probably shouldn't modify it, if you intend to upgrade it (can be automatically upgraded using autoupgrade module).
如果主题是default-bootstrap
,那么是的,如果您打算升级它(可以使用 autoupgrade 模块自动升级),您可能不应该修改它。
Same can be true for 3rd party themes which are actively updated. But usually 3rd party themes don't get upgraded at all, which means you can modify theme templates. Because the templates are sort-of too complex to be extended by a child theme, it is ok to edit them directly. PretaShop doesn't have child-parent theme system. Just edit the templates directly.
对于积极更新的 3rd 方主题也是如此。但通常 3rd 方主题根本不会升级,这意味着您可以修改主题模板。因为模板太复杂了,无法通过子主题进行扩展,所以可以直接编辑它们。PretaShop 没有子父主题系统。直接编辑模板即可。
If you would like your changes to be portable accross themes, then you should probably make a module. Inside the module use special functions to add .js
and .css
files to header:
如果您希望您的更改可以跨主题移植,那么您可能应该制作一个模块。里面的模块使用特殊功能添加.js
和.css
文件标题:
mymodule.php
...
public function install()
{
...
$this->registerHook('displayHeader');
...
}
public function hookDispayHeader()
{
$this->context->controller->addJS($this->_path.'js/script.js');
$this->context->controller->addCSS($this->_path.'css/style.css');
}
If you need a quick way to add, just edit theme's global.css
and global.js
如果您需要快速添加的方法,只需编辑主题global.css
和global.js
You may also add the stysheet and script to autload folder:
您还可以将样式表和脚本添加到自动加载文件夹:
themes/theme1/css/autoload/
and
themes/theme1/js/autoload/
. Files inside these folder will be loaded for all pages.
themes/theme1/css/autoload/
和
themes/theme1/js/autoload/
。这些文件夹中的文件将为所有页面加载。
回答by Cyssoo
Add custom JS or CSS in theme, using this :
在主题中添加自定义 JS 或 CSS,使用:
<link rel="stylesheet" href="{$css_dir}bootstrap/bootstrap.css" type="text/css" media="all" />
<script type="text/javascript" src="{$js_dir}bootstrap.js"></script>
$css_dir links to your theme css directory. $js_dir links to your theme js directory. Assuming you're working on your own theme (or duplicated the default-theme for custom use)
$css_dir 链接到您的主题 css 目录。$js_dir 链接到您的主题 js 目录。假设您正在开发自己的主题(或复制默认主题以供自定义使用)