johan855 johan855 - 1 year ago 128
Smarty Question

Smarty syntax for turning a dictionary into a string and push it into the data layer

I am trying to find a way to pass a string variable (coming from a dictionary) into my website's data layer.

My array is built using the following snippet:

[{foreach from=$orderArticles item="currOrderArticle"}]
[{assign var="currBasePrice2" value=$currOrderArticle-getBasePrice()}]
id: "[{$currOrderArticle-oxorderarticles__oxartnum->value}]",
price: [{$currBasePrice2->getBruttoPrice()}],
quantity: [{$currOrderArticle-oxorderarticles__oxamount->value}]
transaction_id: '[{$order->oxorder__oxordernr-value}]',
transaction_cid: '[{$order->oxorder__oxuserid-value}]',
item_id: '[{$currOrderArticle-oxorderarticles__oxartnum->value}]',
item_value: '[{$basket-getDiscountedNettoPrice()}]',
item_quantity: '[{$currOrderArticle-oxorderarticles__oxamount->value}]'

If I want to pass it to the data layer, I do the following:

ProductsInfo: products_info


This works fine, the issue is that I actually want to modify this array.
I would like to apply the following to it before passing it into the data layer:


But when I try to do it during the push, it does not work:

ProductsInfo: products_info|json_encode|escape:'url'

Answer Source

As I told you in another post, Smarty expressions must be enclosed in delimiters, in your case [{ and }]

Also, as you're using the string in javascript, it must be enclosed within quotes:

        ProductsInfo: '[{products_info|json_encode|escape:'url'}]'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download