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

Linebreaks 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 -> Smarty 3
View previous topic :: View next topic  
Author Message
ilyalyu
Smarty Regular


Joined: 03 Nov 2009
Posts: 72

PostPosted: Mon Feb 01, 2010 11:53 am    Post subject: Linebreaks problem Reply with quote

Code:
function somefunction() { return 1; }
$smarty->register_function('somefunction', 'somefunction');


Code:
{somefunction}
{somefunction}


Smarty output (smarty removes linebreak between two functions):
Code:
11


Expected output (with linebreaks):
Code:
1
1


Evidently, this problem is because of inaccurate use of php openning/closing tags. As I understand, the code above is compiled to something like this:
Code:
<php somefunction(); ?>
<php somefunction(); ?>

If so, linebreak after php closing tag is removed by php.

This whitespace behaviour is real problem. What should I use with this code:
Code:
{somefunction}
{somefunction}

if I want to preserve whitespace?
Back to top
View user's profile Send private message
ChrisFah
Smarty Pro


Joined: 02 Nov 2009
Posts: 159
Location: Traun, Austria

PostPosted: Mon Feb 01, 2010 4:44 pm    Post subject: Reply with quote

What, if i need functions to stay side by side ? So a forced line function is not needed.

Why dont u use something like this:
Code:
function somefunction() { return 1.'<br />'; }
$smarty->register_function('somefunction', 'somefunction');


Lg, Chris
Back to top
View user's profile Send private message
ilyalyu
Smarty Regular


Joined: 03 Nov 2009
Posts: 72

PostPosted: Tue Feb 02, 2010 6:01 am    Post subject: Reply with quote

Quote:
What, if i need functions to stay side by side ? So a forced line function is not needed.


If I need functions to stay side by side, I'll either put them side by side or use {strip} tag.

In my opinion, it would be good if Smarty development team made a decision and made this decision documented:
1. either always preserve whitespaces as they are in template (personally, I prefer this option)
2. or remove whitespaces after all smarty closing tags (i.e. after '}')

I suspect that for now development team does not care about whitespaces. If it happens that smarty closing tag '}' is replaced with php closing tag '?>' during compilation, whitespace is removed (because such is the behaviour of php closing tag). If the above does not happen, whitespace is preserved. The problem is that template designers don't know what happens during compilation (and they should not even think about this). I think the best way is to document this behaviour and not to change it from version to version.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Feb 02, 2010 4:33 pm    Post subject: Reply with quote

This will get fixed, it's an inconsistency in the smarty 3 compiler atm.
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


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

PostPosted: Tue Feb 02, 2010 8:11 pm    Post subject: Reply with quote

The fix for this problem is in the SVN now
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