Re: problem with variable modifiers inside an if statement
| From: | Andrei Zmievski | Date: | Thu, 14 Jun 2001 14:23:38 +0000 |
| Subject: | Re: problem with variable modifiers inside an if statement | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-888@lists.php.net to get a copy of this message | ||
Thanks, I've put it in.
On Thu, 14 Jun 2001, Sam Beckwith wrote:
> 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
>
>
>
> ---
> You are currently subscribed to smarty as: andrei@ispi.net
> To unsubscribe send a blank email to $subst('Email.Unsub')
> Visit Smarty's homepage at
> http://www.phpinsider.com/php/code/Smarty/
-Andrei
It is commonly the case with technologies that you can get
the best insight about how they work by watching them fail.
-- Neal Stephenson