|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Protevis Smarty n00b
Joined: 09 Sep 2009 Posts: 3
|
Posted: Wed Sep 09, 2009 2:34 pm Post subject: New foreach syntax |
|
|
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 |
|
Back to top |
|
Protevis Smarty n00b
Joined: 09 Sep 2009 Posts: 3
|
Posted: Wed Sep 09, 2009 3:18 pm Post subject: |
|
|
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 |
|
Protevis Smarty n00b
Joined: 09 Sep 2009 Posts: 3
|
Posted: Wed Sep 09, 2009 3:26 pm Post subject: |
|
|
Solved this problem myself on testing way
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 |
|
|
|
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
|