|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
FirePanther Smarty n00b
Joined: 30 Apr 2013 Posts: 3
|
Posted: Tue Apr 30, 2013 1:48 am Post subject: Auto-Escape Variables without default-modifiers |
|
|
Hi,
I want to auto-escape my variables, but i don't want to use default-modifiers, because these are to difficult to unescape.
Example:
I have the variable $test with the value "<b>test</b>".
When I use:
{$test}
it should print:
<b>test</b>
And when i want to unescape it, I only have to put an @-char:
{@$var}
With this method it should be more difficult to make a mistake and forget the |escape.
I only need this method for printing, When I use {if $test} it doesn't have to be escaped.
I found the file smarty_internal_templateparser.php and the function yy_r122, but I have no plan how to realize it.
thank you |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
|
Back to top |
|
FirePanther Smarty n00b
Joined: 30 Apr 2013 Posts: 3
|
Posted: Tue Apr 30, 2013 3:44 pm Post subject: |
|
|
hi,
thank you, but i am searching a way to unescape with @$var, instead of $var nofilter.
i worked a long time with the woltlab wcf template parser.
they escape all variables automatically and unescape with an @ char.
but thank you for your post, i will try to edit smarty a bit. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Apr 30, 2013 3:52 pm Post subject: |
|
|
If you insist on a unique syntax, save yourself some headache... create a prefilter that changes {@$foo} to {$foo nofilter} in the templates just before compile. editing smarty just creates trouble for upgrades later on. |
|
Back to top |
|
FirePanther Smarty n00b
Joined: 30 Apr 2013 Posts: 3
|
Posted: Tue Apr 30, 2013 4:02 pm Post subject: |
|
|
thank you, it works
Code: | function at_var_unescape($tpl_source, &$smarty) {
$tpl_source = preg_replace('~\{\@(\$[^\s\}]+)\}~', '{$1 nofilter}', $tpl_source);
return $tpl_source;
} |
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|