1

I need to build table with features in JS and display it on .tpl. I want to transfer array from smarty to JS. At first, i try with variable:

{literal}<script language="javascript" type="text/javascript"> 
<!-- // variable="{/literal}{$product->name|escape:'html':'UTF-8'}{literal}"; 
// --> </script>{/literal}

and it work's. Than i try with array:

{literal}<script language="javascript" type="text/javascript"> 
<!-- // array="{/literal}{$features|json_encode}{literal}"; 
// --> </script>{/literal}

and this solution is not working. Do you have any ideas how can I build array in JS from array in smarty?

1 Answer 1

1

Taken from usage in other tpl in Prestashop, you can do it this way:

<script type="text/javascript">
    taxesArray = new Array();
    {foreach $taxesRatesByGroup as $tax_by_group}
        taxesArray[{$tax_by_group.id_tax_rules_group}] = {$tax_by_group|json_encode};
    {/foreach}
</script>

or for the features example you gave, should be something like:

<script type="text/javascript">
    featuresArray = new Array();
    {foreach $features key=k item=f}
        featuresArray[{$k}] = {$f|json_encode};
    {/foreach}
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.