|
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 |
sagi Smarty Regular
Joined: 30 Jul 2003 Posts: 43
|
Posted: Mon Sep 01, 2003 3:28 pm Post subject: block functions vs arguments/modifiers |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Sep 01, 2003 4:16 pm Post subject: |
|
|
i think "noticable" depends on how many times you call it .
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 |
|
sagi Smarty Regular
Joined: 30 Jul 2003 Posts: 43
|
Posted: Mon Sep 01, 2003 4:30 pm Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Sep 01, 2003 4:50 pm Post subject: |
|
|
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 |
|
|
|
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
|