我正在使用prestashop 1.6。我想在页眉顶部和页脚底部添加Google广告。我尝试了很多方法,但都没有成功。请问如何在prestashop网站上添加脚本? 提前谢谢。
答案 0 :(得分:4)
您需要找到header.tpl文件: https://github.com/PrestaShop/PrestaShop/blob/develop/themes/default-bootstrap/header.tpl
<head>
{$HOOK_HEADER}
<link rel="stylesheet" href="http{if Tools::usingSecureMode()}s{/if}://fonts.googleapis.com/css?family=Open+Sans:300,600&subset=latin,latin-ext" type="text/css" media="all" />
<!--AdWords Code-->
</head>
请记住禁用JS的CCC选项(特别是将JavaScript移到最后):
{literal}{/literal}
标记内的任何内容都不会被解释,而是按原样显示
{literal}
<script type="text/javascript">
// ...
</script>
{/literal}
{ldelim}
和{rdelim}
用于转义模板分隔符,默认为{
和}
:
<script type="text/javascript">
function foo() {ldelim}
// ...
{rdelim}
</script>
给出:
<script type="text/javascript">
function foo() {
// ...
}
</script>
如果您仍有问题,可以尝试覆盖媒体类:
https://gist.github.com/hereswhatidid/8c8edef106ee95138b03
<p>Some HTML goes here</p>
<script type="text/javascript" data-keepinline="true">
// this script will remain here when rendered
alert( "hello!" );
</script>
<script type="text/javascript">
// this script will be forced to the bottom of the page
alert( "hello again!" );
</script>
忽略原始
<?php
Class Media extends MediaCore
{
public static function deferScript($matches)
{
if (!is_array($matches))
return false;
$inline = '';
if (isset($matches[0]))
$original = trim($matches[0]);
if (isset($matches[1]))
$inline = trim($matches[1]);
/* This is an inline script, add its content to inline scripts stack then remove it from content */
if (!empty($inline) && preg_match('/<\s*script(?!.*data-keepinline)[^>]*>/ims', $original) !== 0 && Media::$inline_script[] = $inline)
return '';
/* This is an external script, if it already belongs to js_files then remove it from content */
preg_match('/src\s*=\s*["\']?([^"\']*)[^>]/ims', $original, $results);
if (isset($results[1]) && (in_array($results[1], Context::getContext()->controller->js_files)
|| in_array($results[1], Media::$inline_script_src)))
return '';
/* return original string because no match was found */
return $original;
}
}
答案 1 :(得分:0)
正确的方法应该是使用模块。还要检查函数htmlpurifier是否阻止了脚本标记。
答案 2 :(得分:0)
有点晚了,但是使用{literal} //script here {/literal}
解决了这个问题。只有在脚本中有大括号时才会使用它,但它可以正常工作。