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

"firts" in 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
Vynka
Smarty Rookie


Joined: 30 Apr 2003
Posts: 17
Location: Belgium

PostPosted: Mon Aug 11, 2003 9:54 am    Post subject: "firts" in foreach Reply with quote

Crying or Very sad When i write :
Code:
$smarty.foreach.datas.first
, it does'nt work because "first" is just a method of "section"...

Confused But I can use "Section" because I need "key" then who can resolve thie problem.

Anybody know ? Question
_________________
Au pays des Gloups!
http://www.wishlist.lu
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Aug 11, 2003 10:01 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Vynka
Smarty Rookie


Joined: 30 Apr 2003
Posts: 17
Location: Belgium

PostPosted: Mon Aug 11, 2003 10:07 am    Post subject: Reply with quote

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... Smile
_________________
Au pays des Gloups!
http://www.wishlist.lu
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Aug 11, 2003 10:12 am    Post subject: Reply with quote

your example works fine here *shrug*.
can you post the exact error-message?
what version of smarty do you use?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Vynka
Smarty Rookie


Joined: 30 Apr 2003
Posts: 17
Location: Belgium

PostPosted: Mon Aug 11, 2003 11:12 am    Post subject: Reply with quote

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... Crying or Very sad
_________________
Au pays des Gloups!
http://www.wishlist.lu
Back to top
View user's profile Send private message Visit poster's website
Vynka
Smarty Rookie


Joined: 30 Apr 2003
Posts: 17
Location: Belgium

PostPosted: Mon Aug 11, 2003 11:21 am    Post subject: I have a solution Reply with quote

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 ! Razz
_________________
Au pays des Gloups!
http://www.wishlist.lu
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Aug 11, 2003 11:26 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
koma
Smarty n00b


Joined: 10 Nov 2003
Posts: 2

PostPosted: Mon Nov 10, 2003 5:59 am    Post subject: Reply with quote

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
View user's profile Send private message
koma
Smarty n00b


Joined: 10 Nov 2003
Posts: 2

PostPosted: Mon Nov 10, 2003 6:01 am    Post subject: Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Nov 10, 2003 8:47 am    Post subject: Reply with quote

yes, smarty is case-sensitive.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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