2016-12-01 2 views
0

Später bearbeiten: Dieses Problem wurde behoben. Es scheint, dass das Problem mit einem falsch platzierten Haken war.Escape JS und PHP-Blöcke für Smarty 2

Was ist der richtige und beste Weg, um die JavaScript- und PHP-Blöcke in Smarty 2 zu entkommen?

Ich habe versucht, zu:

  • alle JS Änderung {} mit {} ldelim respectiely {rdelim};
  • add {literal} vor und {/ literal} nach
  • add {php} phpcodehere {/ php}

Keiner von ihnen scheint zu funktionieren.

Hier ist mein Code, der maskiert werden muss:

<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 darf nicht entkommen siehe: http://www.smarty.net/docsv2/en/language.function.ldelim.tp l # id2807434 – JustOnUnderMillions

+0

PHP funktioniert gut mit {php} phpcodehere {/ php}, siehe http://www.smarty.net/docsv2/en/language.function.php.tpl#id2807119 Schauen Sie her: Beispiel 7.29 Und versuchen Sie es nicht Verschachtelung rekursiv, um fehlerhaftes Verhalten zu vermeiden. – JustOnUnderMillions

+0

Die {} von JavaScript muss mit {ldelim} bzw. {rdelim} geändert werden und ich sagte, ich habe das schon gemacht und es funktioniert nicht :). –

Antwort

0

Bitte versuchen:

<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> 
  • ich die einzige Variable, nicht wissen, ist $ra_oldPrice aber ich denke, oben wird zugewiesen Sie