|
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 |
camus546 Smarty n00b
Joined: 16 Oct 2003 Posts: 2
|
Posted: Thu Oct 16, 2003 10:26 pm Post subject: Default and implicit variable modifieres |
|
|
I am converting a xml generating script i use. What I would like to do is to convert all html entites. I can do this in php by using a strtr with get_html_translation_table(HTML_ENTITIES). I was looking for a way to perform the translation implcitly in smarty.
Options:
1. manually translate all vars before assigning to tpl
Painful + slow
2. modify $tpl->assign (or override, etc) to perform processing
3. add var modifier each time
4. have some way to define an implicit modifiers
ie {$title} => {$title|toxml}
an implicit modifer would be ideal since then i only call it on variables i need to. (There is alot of data i pass to the template i might not use).
An output filter wouldnt work since xml tags would be converted too. I just need everything between the tags converted.
thanks |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Oct 16, 2003 10:33 pm Post subject: Re: Default and implicit variable modifieres |
|
|
camus546 wrote: | 2. modify $tpl->assign (or override, etc) to perform processing |
Sounds interesting and reasonable if done as an option. Perhaps a new custom function assign_entitites is more appropriate, though.
I think you can make an output filter work -- with the right regexes, you should be able to target only the content and leave the tags alone. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
|
Back to top |
|
camus546 Smarty n00b
Joined: 16 Oct 2003 Posts: 2
|
Posted: Sun Oct 19, 2003 8:00 pm Post subject: default_modifier caveat |
|
|
It seems that if i use different values for default_modifier, i need to recompile the template to have the modifier be propagated throughout the template. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Oct 20, 2003 10:34 am Post subject: |
|
|
thats true. default_modifier is a compile-time-setting.
you can trick around it if you assign a modifier that dispatches to a function dynamically:
sth. like:
[php:1:4097422a18]
function default_modifier($value) {
global $default_modifier;
if (isset($default_modifier))
return call_user_func($default_modifier, $value);
else
return $value;
}
$smarty->default_modifier = 'default_modifier';[/php:1:4097422a18]
and then set $GLOBALS['default_modifier'] accordingly. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Oct 20, 2003 9:00 pm Post subject: |
|
|
... create different compile_id versions. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Oct 20, 2003 9:13 pm Post subject: |
|
|
boots wrote: | ... create different compile_id versions. |
that's even better. |
|
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
|