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

object and variable

 
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
atomp3
Smarty Regular


Joined: 04 May 2007
Posts: 60

PostPosted: Thu Aug 05, 2010 12:27 pm    Post subject: object and variable Reply with quote

Hi


I have variable {$data->somename}

and than
Code:

      {foreach from=$setall item=item}
      <p>
         {JAttributes d_name=$item.d_name type=$item.oid selected=$data->somename}
      </p>
      {/foreach}


I need to add in loop combination:

Code:
selected = $data->$item.name


which is possible in php but i think not in smarty[/code]


Last edited by atomp3 on Sun Aug 08, 2010 3:28 am; edited 1 time in total
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Aug 05, 2010 4:27 pm    Post subject: Reply with quote

For Smarty 2 you need a workaround

Code:

{foreach from=$setall item=item}
    <p>
     {assign var=foo value=$item.name}
     {JAttributes d_name=$item.d_name type=$item.oid selected=$data->$foo}
    </p>
{/foreach}


In Smarty3 you can use
Code:

{foreach from=$setall item=item}
    <p>
     {JAttributes d_name=$item.d_name type=$item.oid selected=$data->$item.name}
    </p>
{/foreach}
Back to top
View user's profile Send private message
atomp3
Smarty Regular


Joined: 04 May 2007
Posts: 60

PostPosted: Fri Aug 06, 2010 5:49 am    Post subject: Reply with quote

Thanks a lot it's working Smile
Back to top
View user's profile Send private message
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