View previous topic :: View next topic |
Author |
Message |
Vynka Smarty Rookie
Joined: 30 Apr 2003 Posts: 17 Location: Belgium
|
Posted: Mon Aug 11, 2003 9:54 am Post subject: "firts" in foreach |
|
|
When i write : Code: | $smarty.foreach.datas.first | , it does'nt work because "first" is just a method of "section"...
But I can use "Section" because I need "key" then who can resolve thie problem.
Anybody know ? _________________ Au pays des Gloups!
http://www.wishlist.lu |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Aug 11, 2003 10:01 am Post subject: |
|
|
did you give your foreach-loop the name "datas" ?
{foreach from=$datas ...} is not enough, do:
{foreach name=datas from=$datas ...}
then $smarty.foreach.datas.first should work. |
|
Back to top |
|
Vynka Smarty Rookie
Joined: 30 Apr 2003 Posts: 17 Location: Belgium
|
Posted: Mon Aug 11, 2003 10:07 am Post subject: |
|
|
Yes ... My "foreach" loop work correctly but i can't access the "first" ...
Then, i try this :
Code: |
{foreach name=datas item=col from=$SM_GENTAB_Datas[row]}
{if !$smarty.foreach.datas.first}
<td class="Layer-Border" width="1"><img src="images/spacer.gif" width="1" height="1"></td>
{/if}
<td class="Layer-Border" width="1"><img src="images/spacer.gif" width="1" height="1"></td>
<td width="4" height="16"><img src="images/spacer.gif" width="1" height="1"></td>
<td class="Layer-Cel" align="left">{$col}</td>
{/foreach}
|
But an error occure because "first" is'nt a element of "foreach". (only for "section").
PS : Thanks for your quick reponse... _________________ Au pays des Gloups!
http://www.wishlist.lu |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Aug 11, 2003 10:12 am Post subject: |
|
|
your example works fine here *shrug*.
can you post the exact error-message?
what version of smarty do you use? |
|
Back to top |
|
Vynka Smarty Rookie
Joined: 30 Apr 2003 Posts: 17 Location: Belgium
|
Posted: Mon Aug 11, 2003 11:12 am Post subject: |
|
|
I tried again whit the latest version : 2.5.0 (11th april 2003) abd the error is always the same:
Quote: |
Parse error: parse error in /home/thierry/wwwtest/includes/templates_c/%%113/%%1131889139/gentab.tpl.php on line 86
|
Where the line 86 is Code: | <?php if (!$smarty.foreach.datas.first): ?><td>...</td><?php endif; ?>
| in the precompiled file... _________________ Au pays des Gloups!
http://www.wishlist.lu |
|
Back to top |
|
Vynka Smarty Rookie
Joined: 30 Apr 2003 Posts: 17 Location: Belgium
|
Posted: Mon Aug 11, 2003 11:21 am Post subject: I have a solution |
|
|
OK...
I have found a solution. When i try this :
Code: | {if $smarty.foreach.datas.iteration != 1} ... {/if} | ,
it is working !
PS : Thank for your help and your time... An excuse my "approximative" english ! _________________ Au pays des Gloups!
http://www.wishlist.lu |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Aug 11, 2003 11:26 am Post subject: |
|
|
2.5.0? are you sure?
Smarty-2.3.1 had an issue with $smarty.foreach... inside ifs but that is ages ago and definately fixed in Smarty-2.5.0 .
the first line of your compiled template really says:
<?php /* Smarty version 2.5.0, created on ...
??? |
|
Back to top |
|
koma Smarty n00b
Joined: 10 Nov 2003 Posts: 2
|
Posted: Mon Nov 10, 2003 5:59 am Post subject: |
|
|
I have the same problem... my smarty version is 2.5.0 and when I try to use first if IF clause it throws
Fatal error: Smarty: [in db:mod.plk.members.keyword.tpl line 16]: syntax error: invalid attribute name: '$smarty.foreach.isolista.first' (Smarty_Compiler.class.php, line 1334) in /usr/local/lib/php/smarty/Smarty_Compiler.class.php on line 1824
row 16 is
{IF $smarty.foreach.isolista.first != 0}
one row before that
{$smarty.foreach.isolista.first}
if I remove the {IF}...{/IF} section of the code it works fine I get it to print 1 for the first time in loop...
so it on throws error when you are using if with it...
the same problem comes up with last attribute... _________________ Koma |
|
Back to top |
|
koma Smarty n00b
Joined: 10 Nov 2003 Posts: 2
|
Posted: Mon Nov 10, 2003 6:01 am Post subject: |
|
|
OK I just tried something and odd things happened... I have been using syntax where I write smarty if-statements in caps... in foreach first..last that wont work you have to write if in small letters... odd _________________ Koma |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Nov 10, 2003 8:47 am Post subject: |
|
|
yes, smarty is case-sensitive. |
|
Back to top |
|
|