|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
back_to_basic Smarty n00b
Joined: 30 Aug 2012 Posts: 1
|
Posted: Thu Aug 30, 2012 8:28 am Post subject: Help me, Please |
|
|
hi all
In the php. I write
$arr = array(1=>"String");
$i = 1;
echo $arr[$i]
And result is: String
Now, I want write like this in the smarty.
{section name = nProduct loop=$number_product}
{assign var="i" value=$smarty.section.nProduct.iteration}
<input type="text" id="product_name_{$i}" name="product_name_{$i}" placeholder="Tên sản phẩm" size="60" value="{$ary_data.i.product_name_$i}">
{/section}
Then error: unrecognized tag: $ary_data.$i.product_name_$i |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Aug 30, 2012 2:36 pm Post subject: |
|
|
{section} requires numeric indexes starting at 0. Use {foreach}. You also need to assign the variable varname first. Something like:
Code: | {foreach $number_product as $key=>$product}
{assign var="pname" value="product_name_$key"}
<input type="text" id="product_name_{$key}" name="product_name_{$key}" placeholder="Tên sản phẩm" size="60" value="{$ary_data.$key.$pname}">
{/foreach} |
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|