|
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 |
sm@rty Smarty Regular
Joined: 01 Oct 2014 Posts: 65
|
Posted: Tue Mar 31, 2015 7:24 am Post subject: smarty output problem |
|
|
hi
why my output is not true ?
example :
index.tpl
Code: |
{nocache}
{$array = ['key' => 'value',1,2,3]}
----------------------------------
{foreach $array as $key => $value}
{$key} => {$value}
$value@index : {$value@index}
$value@iteration : {$value@iteration}
$value@first : {if $value@first}true{else}null{/if}
$value@last : {if $value@last}true{else}null{/if}
$value@total : {$value@total}
++++++++++++++++++++
{/foreach}
----------------------------------
$value@show : {$value@show}
{/nocache}
|
output :
Code: |
----------------------------------
key => value
$value@index : 0
$value@iteration : 1
$value@first : true$value@last : null$value@total : 4
++++++++++++++++++++
0 => 1
$value@index : 1
$value@iteration : 2
$value@first : null$value@last : null$value@total : 4
++++++++++++++++++++
1 => 2
$value@index : 2
$value@iteration : 3
$value@first : null$value@last : null$value@total : 4
++++++++++++++++++++
2 => 3
$value@index : 3
$value@iteration : 4
$value@first : null$value@last : true$value@total : 4
++++++++++++++++++++
----------------------------------
$value@show : 1
|
output must be like example below :
Code: |
----------------------------------
key => value
$value@index : 0
$value@iteration : 1
$value@first : true
$value@last : null
$value@total : 4
++++++++++++++++++++
0 => 1
$value@index : 1
$value@iteration : 2
$value@first : null
$value@last : null
$value@total : 4
++++++++++++++++++++
1 => 2
$value@index : 2
$value@iteration : 3
$value@first : null
$value@last : null
$value@total : 4
++++++++++++++++++++
2 => 3
$value@index : 3
$value@iteration : 4
$value@first : null
$value@last : true
$value@total : 4
++++++++++++++++++++
----------------------------------
$value@show : 1
|
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Mar 31, 2015 10:03 pm Post subject: |
|
|
Because, as I've said already, Smarty EOL treatment is nontrivial. Some tags eat EOL's, some don't. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Apr 01, 2015 7:46 pm Post subject: |
|
|
This is a known problem. Generated PHP code is enclosed in <?php ?> tags. PHP does eat the line break following the ?> tag.
This is not a problem if none output tags have their own line of template code like
Code: | {if $foo}
text
{/if}
text
|
If this is not the case as in your example the {/if} should be followed by a space to get the right display in the browser.
This will be removed in the upcoming version 3.2 where we will remove all <?php ?> transitions and echo plain template text. |
|
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
|