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

foreach doesnt work...

 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
Piekarz
Smarty n00b


Joined: 30 Dec 2010
Posts: 2

PostPosted: Thu Dec 30, 2010 10:33 pm    Post subject: foreach doesnt work... Reply with quote

Hi, i have a problem with smarty function 'foreach'
I have following code in my .php file:
Code:
$smarty->assign('budynki',$budynki);

variable $budynki is table with indexes like this:
$budynki[0]['lvl']
$budynki[0]['name']
...

In my style file i have following code (copy from manual):
Code:
                     <table>
                        <tr><td></td><td></td></tr>
                        {foreach $budynki as $b}
                        {strip}
                        <tr>
                            <td>{$b.name}</td>
                            <td>{$b.lvl}</td>
                        </tr>
                        {/strip}
                        {/foreach}
                    </table>

And after run script i see only this message:
Quote:

Fatal error: Smarty error: [in view_buildings.xhtml line 40]: syntax error: invalid attribute name: '$budynki' (Smarty_Compiler.class.php, line 1550) in D:\wamp\www\inz\smarty\Smarty.class.php on line 1093


I found on this forum answer about problem with 'invalid attribute name:' and there was that i should turn off "magic quoutes runtime" in php.ini file, but my php.ini has actualy off - "magic quoutes runtime".

What is more i try to use variable like this:
Code:
{$budynki.0.lvl}

and its worked!
What i should do now, because i dont have any idea. I really need use foreach function.
I will be really glad if someone help me ;]
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Dec 30, 2010 11:33 pm    Post subject: Reply with quote

You are using Smarty2.

The
Code:
{foreach $budynki as $b}
syntax of {foreach} is avaible since Smarty3.

For Smarty2 use
Code:
{foreach from=$budynki item=b}


See http://www.smarty.net/docsv2/en/language.function.foreach.tpl
Back to top
View user's profile Send private message
Piekarz
Smarty n00b


Joined: 30 Dec 2010
Posts: 2

PostPosted: Thu Dec 30, 2010 11:45 pm    Post subject: Reply with quote

thx you have right ;]
Back to top
View user's profile Send private message
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 -> Feature Requests 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