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>
JS darf nicht entkommen siehe: http://www.smarty.net/docsv2/en/language.function.ldelim.tp l # id2807434 – JustOnUnderMillions
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
Die {} von JavaScript muss mit {ldelim} bzw. {rdelim} geändert werden und ich sagte, ich habe das schon gemacht und es funktioniert nicht :). –