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

New foreach syntax

 
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 -> Smarty 3
View previous topic :: View next topic  
Author Message
Protevis
Smarty n00b


Joined: 09 Sep 2009
Posts: 3

PostPosted: Wed Sep 09, 2009 2:34 pm    Post subject: New foreach syntax Reply with quote

index.php
Code:
require('smarty/libs/Smarty.class.php');

# $smarty = new Smarty(); // for smarty2
$smarty = new Smarty; // for smarty3

$fields = array("Country", "Town", "Street", "House");

$smarty->assign('field', $fields);
$smarty->display('index.tpl');


index.tpl
This code works on smarty2 fine:
Code:
{foreach from=$fields item="field"}
{$field}
{/foreach}


I see: Country Town Street House. OK.
But on smarty3 when im trying new syntax:
Code:
{foreach $fields as $field}
{$field}
{/foreach}

or old one:

{foreach from=$fields item="field"}
{$field}
{/foreach}

I see nothing and no errors...
Smarty Debug Console
Code:
$field     Smarty_Variable Object (3)
->value = Array (4)
  0 => "Country"
  1 => "Town"
  2 => "Street"
  3 => "House"
->nocache = false
->scope = 0


P.S. btw {nocache} ... {/nocache} works fine, ty for this good new tag Wink
Back to top
View user's profile Send private message
Protevis
Smarty n00b


Joined: 09 Sep 2009
Posts: 3

PostPosted: Wed Sep 09, 2009 3:18 pm    Post subject: Reply with quote

Well, on index.tpl tried:
Code:
{assign var=foo value=[Name, Size, Age]}

{foreach $foo as $var}
{$var}
{/foreach}


And this working good...
Back to top
View user's profile Send private message
Protevis
Smarty n00b


Joined: 09 Sep 2009
Posts: 3

PostPosted: Wed Sep 09, 2009 3:26 pm    Post subject: Reply with quote

Solved this problem myself on testing way Smile

So from old smarty2:
Code:
{foreach from=$fields item="field"}
{$field}
{/foreach}

To new one smarty3:
Code:
{foreach $field as $var}
{$var}
{/foreach}

Where my array on index.php looks
Code:
$fields = array("Country", "Town", "Street", "House");
$smarty->assign('field', $fields);
$smarty->display('index.tpl');
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 -> Smarty 3 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