|
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 |
mindfriction Smarty n00b
Joined: 11 Jan 2006 Posts: 4
|
Posted: Thu Jan 12, 2006 12:08 am Post subject: HELP:creating template with for loop |
|
|
Hi guys and girls,
today is my first day working with Smarty and Im doing 'ok', but I'm unsure on a bit of the logic for a template im trying to create.
Essentially I have a series of select boxes for the closing and opening times from Sunday to Monday populated from arrays; $day, $period $hours. I want to use these arrays to dynamically create the relevant template sections, but dont know how...
My arrays...
[php:1:9f1146588e]
$days = array('Sunday', 'Monday', 'Tuesday' .....
$period = array('open', 'close');
$hours = array('12:00 PM', '12:30 PM', '1:00 PM', '1:15 PM'...);
[/php:1:9f1146588e]
My template so far...
Code: |
<table cellspacing="0" cellpadding="1">
{foreach from=$days item=day}
<tr>
<td class="label">{$form.$day.label} <!-- eg $form.monday.label --></td>
<td class="element">{$form.$day.error} <!-- $form.monday.error --></td>
</tr>
{foreach from=$period key=period}
<tr>
<td class="label">{$form.$day.$period.label} <!-- eg $form.monday.open.label //--></td>
<td class="element">$form.$day.$period.error} <!-- eg $form.mondat.open.error --></td>
</tr>
<tr>
<td colspan="2" class="element">{$form.$day.$period.html} <!-- eg $form.monday.open.html --></td>
</tr>
{/foreach}
{/foreach}
</table>
|
I *think* im on the right track but not sure of the syntax within the loops for creating the right placeholder names. Your help greatly appreciated!
Thanks in advance |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Jan 12, 2006 2:38 am Post subject: |
|
|
It seems like the issue is that Smarty gets confused by your dynamic array accesses. Try a mixed syntax, eg:
{$form[$day].label}
{$form[$day][$period].html} |
|
Back to top |
|
mindfriction Smarty n00b
Joined: 11 Jan 2006 Posts: 4
|
Posted: Thu Jan 12, 2006 11:46 pm Post subject: |
|
|
Hiya boots,
first thank you for taking the time to read my post. I did try your suggestion (below) and I can still cant get Smarty to render my select boxes. I've included a trace of the static array passed to Smarty, as yuo can see the select's are there...
Code: |
{foreach from=$daysArray item=day}
<tr>
<td class="label">{$form[$day].label}</td>
<td class="element">{$form[$day].error}</td>
</tr>
{foreach from=$periodArray item=period}
<tr>
<td class="label">{$form[$day].label} </td>
<td class="element">{$form[$day][$period].html}</td>
</tr>
<tr>
<td colspan="2" class="element">{$form[$day][$period].html}</td>
</tr>
{/foreach} {/foreach}
|
And a print out of the relative portion of the "Static" array...
Code: |
[businessHours] => Array
(
[Sunday] => Array
(
[open] => Array
(
[name] => businessHours[Sunday][open]
[value] =>
[type] => select
[frozen] =>
[required] =>
[error] =>
[label] => open:
[html] => <select name="businessHours[Sunday][open]">
<option value="">Please select...</option>
<option value="0000">12:00 AM</option>
<option value="0015">12:15 AM</option>
<option value="0030">12:30 AM</option>
<option value="0045">12:45 AM</option>
<option value="0100">1:00 AM</option>
<option value="0115">1:15 AM</option>
<option value="0130">1:30 AM</option>
<option value="0145">1:45 AM</option>
...
close] => Array
(
[name] => businessHours[Sunday][close]
[value] =>
[type] => select
[frozen] =>
[required] =>
[error] =>
[label] => close:
[html] => <select name="businessHours[Sunday][close]">
<option value="">Please select...</option>
<option value="0000">12:00 AM</option>
<option value="0015">12:15 AM</option>
<option value="0030">12:30 AM</option>
<option value="0045">12:45 AM</option>
<option value="0100">1:00 AM</option>
<option value="0115">1:15 AM</option>
<option value="0130">1:30 AM</option>
|
|
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Jan 17, 2006 7:24 am Post subject: |
|
|
Hi.
Well, should not this:
Code: | <td class="label">{$form[$day].label} </td> |
rather be:
Code: | <td class="label">{$form[$day][$period].label} </td> |
...but that also assumes that $form is pointing to the businessHours item of the "static" array.
If that's not the issue, please describe the symptons in more detail.
Greetings. |
|
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
|