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

Allow insert functions to trigger modifiers on output
Goto page 1, 2  Next
 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
sma
Smarty Rookie


Joined: 14 Sep 2008
Posts: 9

PostPosted: Sun Sep 14, 2008 9:13 pm    Post subject: Allow insert functions to trigger modifiers on output Reply with quote

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


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Sep 14, 2008 9:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
sma
Smarty Rookie


Joined: 14 Sep 2008
Posts: 9

PostPosted: Sun Sep 14, 2008 9:56 pm    Post subject: Reply with quote

That works wonders, unless you're using caching. And {insert} is useless outside of caching.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Sep 14, 2008 10:08 pm    Post subject: Reply with quote

You can make the processing of that variable dynamic. See example 14-11 of documentation.
Back to top
View user's profile Send private message
sma
Smarty Rookie


Joined: 14 Sep 2008
Posts: 9

PostPosted: Sun Sep 14, 2008 10:15 pm    Post subject: Reply with quote

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


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Sep 15, 2008 3:17 am    Post subject: Reply with quote

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


Joined: 17 Apr 2007
Posts: 1025
Location: Vienna

PostPosted: Mon Sep 15, 2008 9:05 am    Post subject: Reply with quote

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


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Sep 15, 2008 3:02 pm    Post subject: Reply with quote

Celeb a modifier on a block function does not work but also doesn't throw an error.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Sep 15, 2008 3:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
sma
Smarty Rookie


Joined: 14 Sep 2008
Posts: 9

PostPosted: Mon Sep 15, 2008 8:05 pm    Post subject: Reply with quote

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


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Sep 15, 2008 8:52 pm    Post subject: Reply with quote

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


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Sep 16, 2008 7:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
sma
Smarty Rookie


Joined: 14 Sep 2008
Posts: 9

PostPosted: Thu Sep 18, 2008 5:50 am    Post subject: Reply with quote

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


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Sep 18, 2008 6:43 am    Post subject: Reply with quote

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
View user's profile Send private message
sma
Smarty Rookie


Joined: 14 Sep 2008
Posts: 9

PostPosted: Thu Sep 18, 2008 7:52 am    Post subject: Reply with quote

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
View user's profile Send private message
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 -> Feature Requests All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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