|
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 |
c960657 Smarty Regular
Joined: 07 May 2003 Posts: 75 Location: Copenhagen, Denmark
|
Posted: Tue Aug 10, 2004 7:55 am Post subject: Newlines after } are sometimes ignored |
|
|
If you have a template like this
Code: | <pre>
line 1: {if 1}foo{/if}
line 2: {strip}bar{/strip}
line 3: {math equation="987 * x" x=1}
line 4: {include file="foo.tpl"}
line 5: bongo
</pre> |
and another template, foo.tpl, that is completely empty, you get the following output:
Code: | line 1: fooline 2: bar
line 3: 987
line 4: line 5: bongo |
It appears that Smarty sometimes but now always "swallows" the newline after }, if } is the last character on the line. If you add an additional space or some other character to the end of the line in the template shown above, the "line x" labels do appear on seperate lines.
I don't know whether "newline swallowing" is intentional like in PHP (I assume it isn't), but it seems weird that not all tags behave the same in this respect. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sat Aug 14, 2004 11:26 am Post subject: Re: Newlines after } are sometimes ignored |
|
|
c960657 wrote: | I don't know whether "newline swallowing" is intentional like in PHP (I assume it isn't), but it seems weird that not all tags behave the same in this respect. |
the idea behing smarty's newline swallowing is: it should work so, that the output looks as expected.
as a rule of thumb: tags that don't have output swallow a following newline but tags that have output keep it.
for example:
start
{foreach from=$list item=a}<-- this newline would be swallowed
{$a}<-- this newline would be kept
{/foreach}<-- this newline would be kept
end
so you get
start
a1
a2
a3
a4
end
that's the theory. i agree that in practice it looks just weird and incosistent. |
|
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
|