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

Call HTML_QuickForm object dynamically from Smarty foreach?

 
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 -> General
View previous topic :: View next topic  
Author Message
apinomus
Smarty n00b


Joined: 04 Dec 2007
Posts: 2

PostPosted: Tue Dec 04, 2007 8:29 pm    Post subject: Call HTML_QuickForm object dynamically from Smarty foreach? Reply with quote

I'm needing the template to loop through my array of class numbers and write the inputs for each class, resulting in...

{$form_data.p102_complete_sem.html}
{$form_data.p104_complete_sem.html}
{$form_data.p300_complete_sem.html}
etc...

The problem here is that {$form_data.p{$a}_complete_sem.html} isn't proper syntax. Can somebody tell me how I can properly add the $a var as part of my Smarty call so it ends up as {form_data.p102_complete_sem.html} ?

Code:

      /* Start QuickForm file */
      //Create array
      $completed_semester_classes = array(102=>'PSYC 102 Orientation to Psychology',
              104=>'PSYC 104 General Psychology',
              300=>'PSYC 300 Statistics in Psychological Research',
              310=>'PSYC 310 Research Methods in Psychology',
              318=>'PSYC 318 Cognitive Psychology',
              333=>'PSYC 333 Child Psychology',
              350=>'PSYC 350 Abnormal Psychology',
              360=>'PSYC 360 Social Psychology',
              370=>'PSYC 370 Brain and Behavior',
              380=>'PSYC 380 Brain and Pathology',
              618=>'PSYC 618 Exp: Human Learning',
              620=>'PSYC 620 Exp: Sensation, Perception, Cognition',
              622=>'PSYC 622 Exp: Social Behavior',
              624=>'PSYC 624 Exp: Personality');

      //foreach to create inputs for each class
      foreach($completed_semester_classes as $class_number=>$class_name)
      {
              $form->addElement('select', 'p'.$class_number.'_complete_sem', $class_name, $completed_semester_values);
      }
       
      /* Start Smarty code */
      {foreach from=$completed_semester_classes key=a item=b}
              <tr class="{cycle values='odd,even'}" style="font-size:0.8em;">
                      <td>{$form_data.`$a`_complete_sem.html}</td>
              </tr>
      {/foreach}


Thanks!
Back to top
View user's profile Send private message
apinomus
Smarty n00b


Joined: 04 Dec 2007
Posts: 2

PostPosted: Fri Dec 07, 2007 9:46 pm    Post subject: Reply with quote

Bump

Is this just not possible to call another variable inside another? Seems like a pretty basic functionality, I just can't find any documentation on it, either.
Back to top
View user's profile Send private message
Celeb
Administrator


Joined: 17 Apr 2007
Posts: 1025
Location: Vienna

PostPosted: Fri Dec 07, 2007 11:20 pm    Post subject: Reply with quote

Has been solved so many times Wink

Code:
{assign var=foo value="`$bar`_complete_sem.html"}
{$form_data.$foo}

_________________
Darn computers always do what I tell them to instead of what I want them to do.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Sat Dec 08, 2007 1:17 am    Post subject: Reply with quote

Or better yet, assign the data in a way that makes it easy to just loop over and display Smile
Back to top
View user's profile Send private message Visit poster's website
Celeb
Administrator


Joined: 17 Apr 2007
Posts: 1025
Location: Vienna

PostPosted: Sun Dec 09, 2007 4:40 pm    Post subject: Reply with quote

Yeah true, but I just was in the "give them a meal" not "teach them to cook" mood Razz
_________________
Darn computers always do what I tell them to instead of what I want them to do.
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 -> General 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