Re: [SMARTY-DEV] strip problem again
| From: | Jan Rosier | Date: | Mon, 01 Sep 2003 10:58:57 +0000 |
| Subject: | Re: [SMARTY-DEV] strip problem again | ||
| References: | 1 2 3 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-1832@lists.php.net to get a copy of this message | ||
Ah {strip} again ;-)
I will try to explain what I found out before. Hope this helps...
In older versions of Smarty where {strip} isn't a block function, {strip}
eats to many spaces.
See example in
http://lists.php.net/article.php?group=php.smarty.dev&article=1216
Template:
{strip}
<P>
{$firstname} {$lastname}
</P>
{/strip}
Compiled before strip:
<P>
<?php echo $this->_tpl_vars['firstname']; ?>
<?php echo $this->_tpl_vars['lastname']; ?>
</P>
Followed by strip, which first remove leading and trailing spaces and then
remove the newlines
Result:
<P><?php echo $this->_tpl_vars['firstname']; ?><?php echo
$this->_tpl_vars['lastname']; ?></P>
Now the space between firstname and lastname is gone => unwanted
Changing line 396 in Smarty_Compiler.class.php v2.5.0 to "<?php echo
$_return; ?>"; has the following effect on the compiled template before
strip:
<P>
<?php echo $this->_tpl_vars['firstname']; ?> <?php echo
$this->_tpl_vars['lastname']; ?>
</P>
Now strip doesn't remove the spaces before lastname (no leading spaces). The
output now will also have the space between firstname and lastname. This is
correct however this change also effects the line numbering for the error
reporting of Smarty => unwanted
The following change to the strip regex fixed the problem for my
$_strip_search = array(
'%(<\?php echo .*?; \?>)\n%', // remove
newlines after PHP close tags of the echo statments
"!{$ldq}/?strip{$rdq}|[\t ]+$|^[\t ]+!m", // remove
leading/trailing space chars
'%[\r\n]+%m', // remove CRs and
newlines
'%(<\?php echo .*?; \?>)%' // put the
newlines back after PHP close tags
);
$_strip_replace = array(
'\\1',
'',
'',
'\\1' . "\n"
);
Greetings,
Jan Rosier
* To many time we confuse motion with progress. - Cyclops *
----- Original Message -----
From: "Konstantin" <checat@pochtamt.ru>
To: "messju mohr" <messju@lammfellpuschen.de>
Cc: <smarty-dev@lists.php.net>
Sent: Thursday, August 28, 2003 5:49 PM
Subject: Re: [SMARTY-DEV] strip problem again
> > > tabs _AFTER_ the include are not stripped.
> > Smarty_Compiler.class.php 1.278 has this
> > fixed already.
> Sorry, it isn't.
>
> But the place is right.
>
> $_strip_search = array(
> '%([^\\\\]\?>)\n%', // remove newlines after PHP close tags
> "!{$ldq}/?strip{$rdq}|\s+$|^\s+!m", // remove leading/trailing space
chars
> '%[\r\n]+%m', // remove CRs and newlines
> '%([^\\\\]\?>)%'); // replace newlines after PHP close tags
> $_strip_replace = array(
> '\\1',
> '',
> '',
> '\\1' . "\n");
>
> First regexp removes newline and fourth places them back.
> If I remember well there already was a trouble with them.
>
> Yes, I find.
>
> http://lists.php.net/article.php?group=php.smarty.dev&article=1216
> ±b¡àmþÏ)9
> Š2^+http://lists.php.net/article.php?group=php.smarty.dev&article=1217
>
> http://lists.php.net/article.php?group=php.smarty.dev&article=1218
>
> Look there again please.
>
> WBR,
> Konstantin A. Pelepelin
>
> --
> Smarty Development Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>