RFC ::: Patch ::: New line after {else}
| From: | Ferdinand Beyer | Date: | Mon, 17 Jun 2002 15:24:50 +0000 |
| Subject: | RFC ::: Patch ::: New line after {else} | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-4904@lists.php.net to get a copy of this message | ||
Hi folks,
I have found out that spaces (especially new-lines) after smarty tags
are not removed. This feature is very nice since IMO it produces a
better code:
<html>
<head>
{* inserts a default title *}
<title>{$title|default:"Untitled"}</title>
</head>
is currently 'compiled' to
<html>
<head>
<title>...</title>
</head>
PHP automatically removes white space after a PHP tag so I think it
would be nice with Smarty tags, too.
That's why I added this to the _compile_file() method of my
Smarty_Compiler:
/* Remove space character after smarty tags (comment for correct line
no.) */
$template_source = preg_replace("!($ldq.*?$rdq)(\\s)!s",
'\\1' . $this->left_delimiter . '*\\2*' . $this->right_delimiter,
$template_source);
This puts white space after smarty tags in smarty comments so that
newlines are counted properly for $_current_line_no.
The result is a cleaner code:
<html>
<head>
<title>...</title>
</head>
Maybe you should consider to add this functionality (maybe with my
code snippet above) to the cvs code.
It may be that this patch solves the problem already mentioned by
someone in this list: The "new line after {else}" post (don't know the
sender any more)...
--
Ferdinand Beyer
<fbeyer@clickhand.de>