javascript - Prestashop 1.7 - when assigning a variable from Smarty to JS, single quotes are converted
问题描述
When assigning a string variable from Smarty 3.1.33 to JS, single quotes ' are converted to entities ' ;
My code:
{$newOrder = $newOrder|cat :"[{ldelim}\r\n'transactionId':'$orderID'\r\n"|cat: "'transactionAffiliation': 'site.com',\r\n"|cat: "'transactionTotal': '$totalPrice',\r\n"|cat :"'transactionProducts': $orderProducts\r\n {rdelim}]"}
<script>dataLayer = {$newOrder|escape:'html':'UTF-8'};</script>
Get:
<script>dataLayer = [{
'transactionId':'7214'
'transactionAffiliation': 'site.com',
'transactionTotal': '608 грн.',
'transactionProducts': [{
'sku':'17962',
'name':'Детские ходунки M 0591-S микс 4 цвета',
'category':'Ходунки',
'price':445,
'quantity':1
}],
[{
'sku':'28963',
'name':'Планшет обучающий SK 0019',
'category':'Говорящие азбуки',
'price':163,
'quantity':1
}]
}];
</script>
Need (without "' ;"):
<script>dataLayer = [{
'transactionId': '1234',
'transactionAffiliation': 'site.com',
'transactionTotal': 11.99,
'transactionProducts': [{
'sku': 'DD44',
'name': 'T-Shirt',
'category': 'Apparel',
'price': 11.99,
'quantity': 1
}]
}];
</script>
解决方案
由于 prestashop 在 1.7+ 版本中更改了转义方式,因此引起了很多头痛。
您可以尝试像这样删除自动过滤器{$newOrder nofilter}
推荐阅读
- r - 双域潜在增长曲线的选项(可能在 lavaan 中?)
- python - 如何水平和垂直连接两个 alpha 图像?
- xml - 文本不会放在 textview 的中间
- codenameone - 我在css文件里加了一张jpg图片,怎么又去掉了?
- google-chrome-devtools - 离线时来自 Workbox 的 offlineFallback 不起作用
- c# - 有没有办法让某事花费一定的时间c#
- reactjs - 过滤表时排序图标改变方向的意外行为
- matlab - 嵌套 for 循环在所有情况下都太慢?
- python - 在我的电脑中选择文件的 Python 函数
- odbc - 使用具有备用凭据的现有 ODBC 连接