Re: [SMARTY-DEV] {strip}{/strip} unexpected results
| From: | Monte Ohrt | Date: | Thu, 17 Apr 2003 13:28:57 +0000 |
| Subject: | Re: [SMARTY-DEV] {strip}{/strip} unexpected results | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-1217@lists.php.net to get a copy of this message | ||
The compiler inserts extra newlines after '?>' tags in an attempt to
make the template output exactly like the template source. PHP eats
these newlines, so in many cases it is necessary to add a newline so
that the output doesn't get bunched together.
Monte
On Thu, 2003-04-17 at 08:07, Jan Rosier wrote:
> Hello all,
>
> I found that {strip}{/strip} does not always work as you might expect. I
> will try to explain this with an example
>
> In php:
> $smarty->assign('firstname', 'John');
> $smarty->assign('lastname', 'Smith');
>
> Template:
> {strip}
> <P>
> {$firstname}{if $lastname neq ''} {$lastname}{/if}
> </P>
> {/strip}
> {strip}
> <P>
> {$firstname} {$lastname}
> </P>
> {/strip}
>
> Output:
> <P>John Smith</P>
> <P>JohnSmith</P>
>
> The output of the first paragraph is as expected. The second one not. Here
> the space between John and Smith is stripped out
>
> After some digged in Smarty_Compiler.class.php v2.5.0 I found that the
> compiler inserts extra newlines, which interfere with the code that is use
> for strip (line 308 - 317)
>
> I changed line 396: return "<?php echo $_return; ?>\n";
> to: return '<?php echo ' . $_return . '; ?>';
> Now the output of the second paragraph is the same as the output of the
> first paragraph.
>
> Why does the Smarty compiler insert extra newlines in the compiled template?
> Does my change break anything else? If not, then it would be nice if this
> change was put in the distribution as well.
>
> Greetings
> Jan Rosier.
--
Monte Ohrt <monte@ispi.net>