problem with variable modifiers inside an if statement
| From: | Sam Beckwith | Date: | Thu, 14 Jun 2001 06:07:35 +0000 |
| Subject: | problem with variable modifiers inside an if statement | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-887@lists.php.net to get a copy of this message | ||
Greetings,
I am using smarty 1.4.2 and have found a problem with variable modifiers
inside an if statement. The problem occurs when passing a quoted string to
the modifier.
For example, if your php code contains:
<% $var = time(); %>
And your template contains:
{if $var|date_format:"%H" eq "02"}Almost time to stop hacking and go to
bed{/if}
This would cause a PHP parse error since the smarty compiler incorrectly
compiles the "if statement".
I solved the problem by modifying Smarty_Compiler.class.php.
I changed line 466 from:
[^"\'\s()]+ # match any other token that is not any of the above
To this:
[^\s()]+ # match any other token that is not any of the above
I just removed the double and single quotes from this line of the regular
expression and the problem went away. Now smarty will compile the above "if
statement" properly.
Granted, the above "if statement" is worthless in the real world but there
are cases where you may need to use quotes with variable modifiers while in
an "if statement" :)
I have done some testing and so far I have not found any problems with the
modification.
Your milage may vary :)
-Sam