RE: [SMARTY-DEV] Integrating Smarty with Content Management Syste m, questions and design issues (long posting)

From: Date: Thu, 21 Nov 2002 10:35:36 +0000
Subject: RE: [SMARTY-DEV] Integrating Smarty with Content Management Syste m, questions and design issues (long posting)
Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-344@lists.php.net to get a copy of this message
> -----Original Message----- > From: Lee Coltrane [mailto:lee.coltrane@trifolium.com] > > It strikes me that you could probably implement modifiers on > function calls > by taking a modifier list as a parameter to the function > call. The function > gets a reference to the $smarty object, so, inside your > function you could > parse the modifier list, and access the loaded modifiers on the smarty > object, calling the modifier functions yourself on the output of your > function before you print the output. First thought: Your approach might be the only solution for this, as especially custom functions just print out their results and thus it is not possible to use their output as a parameter to the modifier function call. However, it would be nice if template designers would not be confused by having to use modifiers like {$var|modifier} and {myfunc applyModifier="modifier"}, but could use the same syntax for both tasks. It might be kind of a hack, but what about changing the "lexer" in Smarty_Compiler :)? If it detects {$var|mod} (e. g. by locking on the $ sign), nothing would be changed. If the first part before the '|' is a function name, an "implicit function argument", lets say _applyModifier, is set. The function could then evaluate this parameter as proposed. Of course, this would require modifier support at function level. However, this could be eased by providing some kind of helper function for parsing _applyModifier and applying it. But, most important, it would not change the interface and would not break already implemented functions. From a template designers point of view, the same syntax applies for functions and variables. Second thought: Just as with block functions, we could use the PHP output buffer to catch the output of functions and pass it through the modifiers. No support would be needed at function level, existing functions could remain unchanged and would benefit from that; the template designer could apply modifiers to functions as well. The Smarty_Compiler would have to be changed, as it would have to check for modifiers in function tags and insert the necessary code for buffering output, passing it through the modifiers and printing the result. Of course, it would be best if functions were not allowed to print out their results, but instead had to return it as strings. That way, one could handle functions the same way as variables. However, this is a change in the interface (or architecture?) and probably not feasible. Best regards, Matthias (Guess now I am supposed to implement it and need to understand all the regexps in the compiler :)?)

« previous php.smarty.dev (#344) next »