| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
Incrementally number in a Smarty template | |||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
Incrementally number in a Smarty template
We are trying to put a conversion script in our order_message.tpl file, but we need to increment a number in the script for each item. I am familiar with {foreach} but do not know how to do this specific task.
************************* Base Script Example ************************* <script type="text/javascript"> var productDetailsObj = {ldelim} {foreach from=$orders.0.products item=prod} '1' : {ldelim} 'id' : {$prod.productid}, 'price': {$prod.price}, 'qty': {$prod.amount} {rdelim}, {/foreach} {rdelim}; </script> ************************* End Base Script Example ************************* See that '1' in the script, directly under the {foreach} statement? That's the number I need to increment. Here's an example of a working script rendered output: <script type="text/javascript"> var productDetailsObj = { '1' : { 'id' : 12345, 'price': 49.99, 'qty': 1 }, '2' : { 'id' : 23456, 'price': 19.99, 'qty': 4 }, '3' : { 'id' : 34567, 'price': 109.99, 'qty': 2 }, }; </script> |
|||||||
#2
|
|||||||||
|
|||||||||
Re: Incrementally number in a Smarty template
I think you can make use of the iteration property. To do this I believe your foreach loop needs a name:
Code:
Another idea is to assign a variable and increment it yourself each time: Code:
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey XcartGuru X-cart Tutorials | X-cart 5 Tutorials Check out the responsive template for X-cart. |
|||||||||
|
#3
|
|||||||
|
|||||||
Re: Incrementally number in a Smarty template
Thank you! I tried the second option and it appears to be working well.
|
|||||||
|
|||
X-Cart forums © 2001-2020
|