View Single Post
  #1  
Old 03-13-2015, 10:28 AM
 
MAPerformance Admin MAPerformance Admin is offline
 

Advanced Member
  
Join Date: Jun 2013
Posts: 44
 

Default 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>
__________________
X-cart 4.4.3 Gold
Modern Automotive Performance
Reply With Quote