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

smarty output problem

 
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
sm@rty
Smarty Regular


Joined: 01 Oct 2014
Posts: 65

PostPosted: Tue Mar 31, 2015 7:24 am    Post subject: smarty output problem Reply with quote

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


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Mar 31, 2015 10:03 pm    Post subject: Reply with quote

Because, as I've said already, Smarty EOL treatment is nontrivial. Some tags eat EOL's, some don't.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Apr 01, 2015 7:46 pm    Post subject: Reply with quote

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
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 -> 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