Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Help me, Please

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
back_to_basic
Smarty n00b


Joined: 30 Aug 2012
Posts: 1

PostPosted: Thu Aug 30, 2012 8:28 am    Post subject: Help me, Please Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Aug 30, 2012 2:36 pm    Post subject: Reply with quote

{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
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP