[英]Smarty in javascript in prestashop template
I am trying to create data layer with id's of products in prestashop cart page (.tpl file). 我正在尝试在prestashop购物车页面(.tpl文件)中使用产品ID创建数据层。
Here's smarty code that displays products id's added to cart 这是显示添加到购物车的产品ID的巧妙代码
{foreach $products as $product}
{$product.id_product}
{/foreach}
It displays it in this way: 123 284 495 392 它以这种方式显示:123 284 495 392
I would like to make id's appear in script this way: 我想以这种方式使id出现在脚本中:
{literal}
<script>
gtag('event', 'page_view', {'send_to': 'AW-XXXXXXXX',
'ecomm_prodid': '123,284,495,392',
'ecomm_pagetype': 'cart',
'ecomm_totalvalue': '{/literal}{displayPrice price=$total_products_wt}{literal}'
});
</script>
{/literal}
You could add a not last item
conditional, within your foreach loop like this : 您可以在您的foreach循环中添加条件
not last item
,如下所示:
{literal}
<script>
gtag('event', 'page_view', {'send_to': 'AW-XXXXXXXX',
'ecomm_prodid': [{/literal}{foreach from=$products item=product name=prodid}'{$product.id_product}'{if $smarty.foreach.prodid.last}{else},{/if}{/foreach}{literal}],
'ecomm_pagetype': 'cart',
'ecomm_totalvalue': '{/literal}{displayPrice price=$total_products_wt}{literal}'
});
</script>
{/literal}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.