Re: [SMARTY] RFC ::: Patch ::: New line after {else}
| From: | Monte Ohrt | Date: | Mon, 17 Jun 2002 18:08:40 +0000 |
| Subject: | Re: [SMARTY] RFC ::: Patch ::: New line after {else} | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-4905@lists.php.net to get a copy of this message | ||
Smarty comments on a line by themselves leave a blank line, that is a known issue that is yet to be fixed. That should be the only one, the rest of the Smarty tags should work as expected.
example:
<foo>
{if ...}
yes
{else}
no
{/if}
</foo>
Should result in:
<foo>
yes
</foo>
However, if you have any extra spaces _after_ a Smarty tag, those spaces will get rendered! Removing extra spaces by default would not be good. What if you are not rendering an HTML page, but an e-mail message where you want those extra spaces?
If you want to tidy up your HTML output, use the trimwhitespace output filter.
Monte
Ferdinand Beyer wrote:
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>-- Monte Ohrt <monte@ispi.net> Director of Technology, ispi Inc.