Closed coarsy closed 7 years ago
Hi again,
i tried this one:
[{foreach $sArticles as $article name=google}'{$article.articleID|escape}'{if not $smarty.foreach.google.last},{/if} {/foreach}]
But it ends in this output:
"google_tag_params": { "ecomm_prodid": "['496', '275', '333', '332', '331', '273', '264', '189', '161', '91', '67' ]" }
Need a possibility to remove the " before the [...
Thanks and best,
Chris
Hello coarsy,
with the latest commit the plugin checks the property value for type of array, int or float and subsequently won't escape the value if true. So you had the right idea already. To achieve the wanted result you can set the value for the property as follows:
["{/literal}{foreach $sArticles as $sArticle}{if !$sArticle@first}{34|chr}{/if}{$sArticle.ordernumber}{if !$sArticle@last}{34|chr},{/if}{/foreach}{literal}"]
Now for a quick explanation what this will do. With the outer brackets and quotes we get json_decode to read this as an array. Then the smarty compiler comes into play. Since we close the literal tag everything following will be compiled. Then we start the loop. For the first iteration we won't need an opening quote since we already have one. Notice how we use {34|chr} instead of the quote char. That's to have json_decode still return type of array in the beginning. Then there's our value for the iteration, that's ordernumber. We check for the last iteration to not print a closing quote since we have one at the end already. Also we don't want a trailing comma. Then we just close the loop and open the literal tag again. The nice thing about that solution is that it is pretty failproof. If there's nothing to iterate, the value will just be [""].
Now hopefully we can find a way to streamline cases like that in the future. I'm thinking of maybe a custom smarty function or modifier. For the moment this should do the trick natively and without any issues.
It should be able to add the google_tag_params to use the complete remarketing adwords tags too.
More information can be found here:
https://developers.google.com/adwords-remarketing-tag/parameters
Maybe there must be a own special variable for the dataLayer configuration in the backend to get the listing of the product ids in product list view.
Thanks and best,
Chris