Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Default and implicit variable modifieres

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
camus546
Smarty n00b


Joined: 16 Oct 2003
Posts: 2

PostPosted: Thu Oct 16, 2003 10:26 pm    Post subject: Default and implicit variable modifieres Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Oct 16, 2003 10:33 pm    Post subject: Re: Default and implicit variable modifieres Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Fri Oct 17, 2003 12:41 am    Post subject: Reply with quote

http://smarty.php.net/manual/en/variable.default.modifiers.php ??
Back to top
View user's profile Send private message Send e-mail Visit poster's website
camus546
Smarty n00b


Joined: 16 Oct 2003
Posts: 2

PostPosted: Sun Oct 19, 2003 8:00 pm    Post subject: default_modifier caveat Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Oct 20, 2003 10:34 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Oct 20, 2003 9:00 pm    Post subject: Reply with quote

... create different compile_id versions.
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Oct 20, 2003 9:13 pm    Post subject: Reply with quote

boots wrote:
... create different compile_id versions.


that's even better. Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP