View previous topic :: View next topic |
Author |
Message |
sma Smarty Rookie
Joined: 14 Sep 2008 Posts: 9
|
Posted: Sun Sep 14, 2008 9:13 pm Post subject: Allow insert functions to trigger modifiers on output |
|
|
Our site is obscenely dynamic, so we make heavy use of {insert} for dynamic information, and caching of everything else. Currently, it's impossible to run the output of the insert statement through a gauntlet of modifiers, short of writing our own processor and bastardizing _run_mod_handler. This is specifically a problem when the same information needs different modifications based on its use. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Sep 14, 2008 9:34 pm Post subject: |
|
|
Use the assign attribute of the insert tag to store its result in a Samrty varibale. You can run this variable then through the required modifiers. |
|
Back to top |
|
sma Smarty Rookie
Joined: 14 Sep 2008 Posts: 9
|
Posted: Sun Sep 14, 2008 9:56 pm Post subject: |
|
|
That works wonders, unless you're using caching. And {insert} is useless outside of caching. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Sep 14, 2008 10:08 pm Post subject: |
|
|
You can make the processing of that variable dynamic. See example 14-11 of documentation. |
|
Back to top |
|
sma Smarty Rookie
Joined: 14 Sep 2008 Posts: 9
|
Posted: Sun Sep 14, 2008 10:15 pm Post subject: |
|
|
Is that more or less efficient than using the builtin insert function? We already have a non-cache block called, oddly enough, {nocache}. Every time that block is called, though, Smarty has to go through and process everything in it anew. An {insert} function could bypass most of the processing. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Sep 15, 2008 3:17 am Post subject: |
|
|
My thought was that when caching is used you use just {nocache}($varfrominsert|modifiers}{/nocache}.
I don't think that an {insert} is quicker then a {nocache}. What processing could you bypass with an {insert} ? |
|
Back to top |
|
Celeb Administrator
Joined: 17 Apr 2007 Posts: 1025 Location: Vienna
|
Posted: Mon Sep 15, 2008 9:05 am Post subject: |
|
|
To avoid the assignment you could do this (I think):
Code: | {nocache|modifiers}{insert ...}{/nocache} |
_________________ Darn computers always do what I tell them to instead of what I want them to do. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Sep 15, 2008 3:02 pm Post subject: |
|
|
Celeb a modifier on a block function does not work but also doesn't throw an error. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Sep 15, 2008 3:26 pm Post subject: |
|
|
Okay, on block functions modifiers have to be placed on the closing tag.
Code: | {nocache} ..... {/nocache|modifiers} |
But it does not work with the {insert...} inside the no cache. The modifier will not run at the content but on the place holder for cache insert. |
|
Back to top |
|
sma Smarty Rookie
Joined: 14 Sep 2008 Posts: 9
|
Posted: Mon Sep 15, 2008 8:05 pm Post subject: |
|
|
A block has to read through every last byte in the stuff between to see if Smarty needs to process or not. With insert, there's no in between stuff. There's no unnecessary subprocessing looking for variables, blocks, includes, conditions, etc. Just the single command that ends with '}' and the PHP function. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Sep 15, 2008 8:52 pm Post subject: |
|
|
Modifiers on block functions normally will run on every content between the block tags, even if it is just pain text.
However if you have caching enabled the {insert} tag will be compiled to a place holder (cache insert). In this case the modifier will run on this place holder and not as expected on the content of the {insert} tag. That is what I wanted to say. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Sep 16, 2008 7:19 pm Post subject: |
|
|
sma comming back to your initial problem.
Why don't you use instead of an insert function a registered functin or plugin?
You could use it dynamically with modifiers like this
Code: | {nocache}{yourfunction|modifier...}{/nocache} |
|
|
Back to top |
|
sma Smarty Rookie
Joined: 14 Sep 2008 Posts: 9
|
Posted: Thu Sep 18, 2008 5:50 am Post subject: |
|
|
For {nocache}{function}{/nocache}, smarty would have to process the nocache, then process the function and any modifiers attached to it. By making it so insert functions can call modifiers, you remove one step of that. Further, it doesn't have to search for the close tag, since inserts don't have them. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Sep 18, 2008 6:43 am Post subject: |
|
|
sma I have spent some time to look for a solution for that. The problem is how to attach the modifiers to the {insert...} tag syntax....
I know that the {nocache} {/nocache} solution is not the most optimal, because it does require one additional disk read. The parsing of the {nocache} tags is not the problem because this happens just once when the template is being compiled. |
|
Back to top |
|
sma Smarty Rookie
Joined: 14 Sep 2008 Posts: 9
|
Posted: Thu Sep 18, 2008 7:52 am Post subject: |
|
|
Could create a new operator that applies modifiers to the output of a function, which could also work with custom functions that take input. For example:
{insert name="graph" x="a" y="b";modifier|modifier|modifier}
and
{somefunction arg1="word" arg2=2785;modifier|modifier|modifier}
...and/or just create a php public function to be called by the insert function.
Last edited by sma on Thu Sep 18, 2008 5:55 pm; edited 1 time in total |
|
Back to top |
|
|