Forum
Looping through array in template
Trying to loop through an array in a form template but currently only able to output the first item in the array, although it does output as many times as there are items:
<?php
PerchSystem::set_var('product_list', $itemList);
perch_form('cart.html');
?>
Array content looks like this:
Array ( [0] => 3 x Blackmagic Ursa Mini Pro 4.6k EF [1] => 1 x Go Pro Hero 3 Black Edition )
Template looks like this:
<perch:repeater id="product_list">
<perch:forms id="product_list" encode="false" />
</perch:repeater>
Output:
3 x Blackmagic Ursa Mini Pro 4.6k EF 3 x Blackmagic Ursa Mini Pro 4.6k EF
Hello Rob,
To render an array with a repeater tag your array should be made up of arrays like this:
Template:
Brill Thank you Hussein,
How would you perform that dynamically, as looping through adds each iteration into the array and I don't know the contents of the cart:
Magento Development Developers. Expand your online store with Magento developer tools, shopping cart and payment integration services worldwide. https://eminentcoders.com/magento-development-toronto/
You need to assign keys to the array elements (so you can use the keys as IDs in the template):
In your case you can actually use:
And in your form template:
Awesome thank you!!