我有以下Smarty模板,它的整體顯示它會生成一些JavaScript。替代Smarty動態JavaScript的{literal}標籤
正如你所看到的,我開放{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}
退房[liuchangjohn的評論](http://www.smarty.net/forums/viewtopic.php?t=150)上使用Smarty的前置過濾器,以生成腳本標記。總體而言,語法更清晰。 – Mathletics 2013-02-22 17:13:33
@Mathletics從那時起已經過去了幾年,這種黑客應該不再需要了。 – 2013-02-23 22:29:29