我有以下 Smarty 模板,该模板完整显示,可生成一些 JavaScript。
如您所见,我在整个代码片段中都打开{literal}
和关闭{/literal}
标签,这看起来有点混乱和不守规矩。有没有更好的方法来编写它,使代码在将来必须更改时显得更整洁和更易于管理?
{literal}
<script type="text/javascript">
var _roi = _roi || [];
// Base Order Details
_roi.push(['_setMerchantId', '{/literal}{$merchant_id}{literal}']);
_roi.push(['_setOrderId', '{/literal}{$order_id}{literal}']);
_roi.push(['_setOrderAmount', '{/literal}{$order_total}{literal}']);
_roi.push(['_setOrderNotes', '{/literal}{$order_notes}{literal}']);
// Line Items
{/literal}
{foreach from=$line_items item=line name=items}
{literal}
_roi.push(['_addItem',
'{/literal}{$line.sku}{literal}',
'{/literal}{$line.title}{literal}',
'{/literal}{$line.category_id}{literal}',
'{/literal}{$line.category}{literal}',
'{/literal}{$line.price}{literal}',
'{/literal}{$line.quantity}{literal}'
]);
{/literal}
{/foreach}
{literal}
// Submit Transaction to SDC ROI tracker
_roi.push(['_trackTrans']);
</script>
<script type="text/javascript" src="{/literal}{$url}{literal}"></script>{/literal}