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

block functions vs arguments/modifiers

 
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 -> Plugins
View previous topic :: View next topic  
Author Message
sagi
Smarty Regular


Joined: 30 Jul 2003
Posts: 43

PostPosted: Mon Sep 01, 2003 3:28 pm    Post subject: block functions vs arguments/modifiers Reply with quote

I wrote a translation library that uses block function to get the string - like {t}this is a test{/t} (see the tips and tricks forum if you're interested).

In the compiled template I saw that each instance calls the ob functions. I wondered if there will be noticeable performance difference if I used a normal function with an argument, or a modifier instead?
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Mon Sep 01, 2003 4:16 pm    Post subject: Reply with quote

i think "noticable" depends on how many times you call it Wink.
you will get best performance if you do the translation in a prefilter and use your language as compile_id. then you end up with one compiled template for each language and only do the translation at compile-time of the template and not at display time.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
sagi
Smarty Regular


Joined: 30 Jul 2003
Posts: 43

PostPosted: Mon Sep 01, 2003 4:30 pm    Post subject: Reply with quote

I call it about 10 times in each request right now (might increase in the future).

I can't use prefilter because the function output is dynamic - I use gettext, and it can be called like {t name="sagi"}your name is: %1{/t} - will replace %1 with sagi. It also might have different result for plural strings.
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Mon Sep 01, 2003 4:50 pm    Post subject: Reply with quote

but you can write a prefilter that translates
"{t}my name is {$name}{/t}"
to
"mein name ist {$name}"

or one that translates

"{t name=$foo}my name is %1{/t}"
to
"my name is {$foo}"
for each language.

of course you have to be much more thoughtful about what's available at compile-time and what's not when using a pre-filter instead of a block-function. i don't want to push you in that direction if you prefer block-functions.
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 -> Plugins 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