|
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 |
apinomus Smarty n00b
Joined: 04 Dec 2007 Posts: 2
|
Posted: Tue Dec 04, 2007 8:29 pm Post subject: Call HTML_QuickForm object dynamically from Smarty foreach? |
|
|
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 |
|
apinomus Smarty n00b
Joined: 04 Dec 2007 Posts: 2
|
Posted: Fri Dec 07, 2007 9:46 pm Post subject: |
|
|
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 |
|
Celeb Administrator
Joined: 17 Apr 2007 Posts: 1025 Location: Vienna
|
Posted: Fri Dec 07, 2007 11:20 pm Post subject: |
|
|
Has been solved so many times
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sat Dec 08, 2007 1:17 am Post subject: |
|
|
Or better yet, assign the data in a way that makes it easy to just loop over and display |
|
Back to top |
|
Celeb Administrator
Joined: 17 Apr 2007 Posts: 1025 Location: Vienna
|
Posted: Sun Dec 09, 2007 4:40 pm Post subject: |
|
|
Yeah true, but I just was in the "give them a meal" not "teach them to cook" mood _________________ Darn computers always do what I tell them to instead of what I want them to do. |
|
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
|