Re: [SMARTY] Weird problem with if-else

From: Date: Mon, 26 Sep 2005 22:10:44 +0000
Subject: Re: [SMARTY] Weird problem with if-else
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-13061@lists.php.net to get a copy of this message
Hi. In your segment: {foreach from=$week item="day"} {if $day.blank eq true} <td>&nbsp;</td> {* {else} *} {foreachelse} {include file="calendar_cell_bit.tpl"} {/if} {/foreach} you are improperly nesting your if block in your foreach block. Specifically, your if block is contained in your foreach block -- which is acceptable; however you then try to insert the foreachelse into the if/else/endif block which would make the foreach contained in the if block ... which would contradict the original containment. HTH --- "A.J. Brown" <aj@bitnotion.com> wrote: > Rafa, > > I'm not sure this would achieve what I'm looking to do. Let me > explain further. What this template does is create the rows of a > table for a calendar. The section I'm having trouble with is the > part that loops through the array of days for the given week and > determines whether to show a blank cell (I.E. a date block which has > no date for this month), or to show the "calendar_cell_bit". It > knows this by looking at the $day['blank'] value during each > iteration. If this value is true, it will show the blank cell. If > it's false, it will parse the "calendar_cell_bit.tpl" file and output > that instead. > > It also appears that your solution wouldn't compile, since the > {foreachelse} comes within the {if} block, instead of a matching > {foreach}. Is this correct? > > > > Sincerely, > > A.J. Brown > BitNotion Technologies > aj@bitontion.com > > ----- Original Message ----- > From: Rafa Vidal > To: 'A.J. Brown' > Sent: Monday, September 26, 2005 3:38 PM > Subject: RE: [SMARTY] Weird problem with if-else > > > > > > > -----Mensaje original----- > De: A.J. Brown [mailto:aj@bitnotion.com] > Enviado el: lunes, 26 de septiembre de 2005 18:52 > Para: smarty-general@lists.php.net > Asunto: [SMARTY] Weird problem with if-else > > > > Hello Everyone, > > > > I'm having a weird Smarty compilation error with the following > section of > > code. The error is "unexpected {else}": > > > > {foreach from=$calendar.weeks item="week"} > > <tr class="calendar_week"> > > {foreach from=$week item="day"} > > {if $day.blank eq true} > > <td>&nbsp;</td> > > {* > > {else} > > *} > > {foreachelse} > > {include file="calendar_cell_bit.tpl"} > > {/if} > > {/foreach} > > </tr> > > {/foreach} > > > > > > At first I thought the problem was with the included file, but I > still get > > the error even if I comment out that line. There are no other {if} > > > statements anywhere else in this template, so I'm positive it's not > a > > nesting or unclosed {if} problem. > > > > When I use the following code instead, it works perfectly: > > > > {foreach from=$calendar.weeks item="week"} > > <tr class="calendar_week"> > > {foreach from=$week item="day"} > > {if $day.blank eq true} > > <td>&nbsp;</td> > > {/if} > > {if $day.blank eq false} > > {include file="calendar_cell_bit.tpl"} > > {/if} > > {/foreach} > > </tr> > > {/foreach} > > > > > > What's up with this? > > > > Sincerely, > > > > A.J. Brown > > BitNotion Technologies > > aj@bitontion.com > > > > ----- Original Message ----- > > From: "Oscar Fernandez Sierra" <oscar@el-mundo.net> > > To: "v3rb0" <mailto.v3rb0@gmail.com> > > Cc: <smarty-general@lists.php.net> > > Sent: Sunday, September 25, 2005 2:24 PM > > Subject: Re: [SMARTY] Why do I only show two items when looping > > > > > > Recordad que en el foro de alonsocampeon tenéis que entrar para > generar la > > página de opiniones > > > > > http://farton.elmundo.int:9090/elmundo/opiniones/index_opiniones.html?anio_creacion_opiniones=2005&opiniones=alonsocampeon > > -- > > Oscar Fernandez Sierra | Mundinteractivos - El Mundo | > > Area de Internet | Pradillo, 42 | > > oscar@el-mundo.net | 28002 - Madrid (SPAIN, EU) | > > http://www.elmundo.es/ | Tel: (+34) 915864800 (Ext: 4616) > | > > > > > > On Sun, 25 Sep 2005, v3rb0 wrote: > > > > > use > > > > > > <ul class="showIt" id="mn1"> > > > {foreach from=$links_list->mCategories[cat] item=item key=key} > > > <li class="subLinks"> > > > <a href="{$links_list->mLinks[cat][link].linkURL}"> > > > {$links_list->mLinks[cat][link].linkTitle} > > > </a> > > > </li> > > > {/foreach} > > > </ul> > > > > > > insetad of > > > > > > {section name=link loop=$links_list->mCategories[cat]} > > > > > > ... > > > {/section} > > > > > > -- > > > Smarty General Mailing List (http://smarty.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > -- > > Smarty General Mailing List (http://smarty.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > > Smarty General Mailing List (http://smarty.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com

« previous php.smarty.general (#13061) next »