我试图更改我的订单 - confirmation.tpl,之后显示几个错误我尝试添加facebook像素代码来跟踪订单。
我的更改
我添加了OrderConfirmationController.php
$cart = new Cart((int)($this->id_cart));
self::$smarty->assign(array(
'_order' => $this->id_order,
'_value' => $cart->getOrderTotal()
));
之后我添加了order-confirmation.tpl
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','//connect.facebook.net/en_US/fbevents.js');
fbq('init', 'xxxxxxxxxxxxxx');
fbq('track', "PageView");
fbq('track', 'Purchase', {value: {$_value}, currency: 'USD'});
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=1445570592421898&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
如你所见,我试图通过$ _value获得价值
错误是
Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "/var/www/presta/themes/mytheme/order-confirmation.tpl" on line 43
"!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?" - Unexpected ".", expected one of: "","" , ")" <-- thrown in
/var/www/presta/tools/smarty/sysplugins/smarty_internal_templatecompilerbase.php on line 43
谢谢
答案 0 :(得分:8)
我修正了改变那部分的问题,也许有人需要有一天facebook Pixel的事情:)
关于order-confirmation.tpl因为聪明而需要添加 {literal}
!-- Facebook Pixel Code -->
<script>
{literal}
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','//connect.facebook.net/en_US/fbevents.js');
fbq('init', '1445570592421898');
fbq('track', "PageView");
fbq('track', 'Purchase', {value: {/literal}'{$_value}'{literal}, currency: 'USD'});
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=1445570592421898&ev=PageView&noscript=1"
/></noscript>{/literal}
<!-- End Facebook Pixel Code -->
答案 1 :(得分:4)
在Smarty模板中,{和}大括号将被忽略,只要它们被空格包围。
所以只需在每个大括号前后插入一个空格:
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s) { if(f.fbq)return;n=f.fbq=function() { n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments) } ;if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s) } (window,
document,'script','//connect.facebook.net/en_US/fbevents.js');
fbq('init', '0123456789012345');
fbq('track', "PageView");</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=0123456789012345&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->