2016-12-01 37 views
0

稍后修改:此问题已得到解决。这似乎是一个错误的钩子问题。Smarty 2的Escape JS和PHP块

什么是避免Smarty 2中的JavaScript和PHP块的正确和最好的方法?

我曾尝试:

  • 变化每JS {}以{} ldelim {respectiely} rdelim;
  • 加{}文字和之前{/文字}后
  • 加{} PHP {phpcodehere/PHP}其中

无似乎工作。

这里是我的代码需要被转义:

<script> 
    var _ra = _ra || {}; 
    _ra.sendProductInfo = { 
     "id": "{$product.product_id}", 
     "name": "{$product.product}", 
     "url": "{$config.current_url|fn_url}", 
     "img": "{$product.main_pair.detailed.image_path}", 
     {if $ra_oldPrice == $product.price or not is_numeric($ra_oldPrice)} 
     "price": "{if $product.list_price > $product.price}{$product.list_price}{else}{$product.price}{/if}", 
     "promo": "{if $product.list_price > $product.price}{$product.price}{else}0{/if}", 
     {else} 
     "price": "{$ra_oldPrice}", 
     "promo": "{$product.price}", 
     {/if} 
     "brand": false, 
     "category": [{ 
      "id": "{$catid}", 
      "name": "{$product.main_category|fn_get_category_name}", 
      "parent": false, 
      "breadcrumb": [] 
     }], 
     "inventory": { 
      "variations": false, 
      "stock": "{$product_amount = $product.inventory_amount|default:$product.amount}{if ($product_amount <= 0 || $product_amount < $product.min_qty) && $settings.General.inventory_tracking == "Y"}0{else}1{/if}" 
     } 
    }; 
</script> 
+0

JS一定不能逃避看到:http://www.smarty.net/docsv2/en/language.function.ldelim.tp l#id2807434 – JustOnUnderMillions

+0

PHP可以{php} phpcodehere {/ php}正常工作,请参阅http://www.smarty.net/docsv2/en/language.function.php.tpl#id2807119看看这里:Example 7.29并且尽量不要嵌套rekursive避免越野行为。 – JustOnUnderMillions

+0

JavaScript的{}必须分别用{ldelim} {rdelim}更改,我说我已经完成了这个工作,但它不工作:)。 –

回答

0

请尝试:

<script data-no-defer> 
    var _ra = _ra || {$ldelim}{$rdelim}; 
    _ra.sendProductInfo = {$ldelim} 
     id: {$product.product_id}, 
     name: '{$product.product|escape:'javascript'}', 
     url: '{$config.current_url|fn_url}', 
     img: '{$product.main_pair.detailed.image_path}', 
     {if $ra_oldPrice == $product.price or not is_numeric($ra_oldPrice)} 
     price: {if $product.list_price > $product.price}{$product.list_price}{else}{$product.price}{/if}, 
     promo: {if $product.list_price > $product.price}{$product.price}{else}0{/if}, 
     {else} 
     price: {$ra_oldPrice}, 
     promo: {$product.price}, 
     {/if} 
     brand: false, 
     category: [{$ldelim} 
      id: {$product.main_category}, 
      name : '{$category_name=$product.main_category|fn_get_category_name}{$category_name|escape:'javascript'}', 
      parent: false, 
      breadcrumb: [] 
     {$rdelim}], 
     inventory: {$ldelim} 
      variations: false, 
      stock: {$product_amount = $product.inventory_amount|default:$product.amount}{if ($product_amount <= 0 || $product_amount < $product.min_qty) && $settings.General.inventory_tracking == "Y"}0{else}1{/if} 
     {$rdelim} 
    {$rdelim}; 
</script> 
  • 我不知道的唯一的变量是$ra_oldPrice,但我想通过上面分配你