|
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 |
toma Smarty Regular
Joined: 25 Apr 2003 Posts: 62
|
Posted: Fri Mar 23, 2007 10:32 pm Post subject: Rewrite unknown functions to a default handler ...prefilter? |
|
|
I'm attempting to embed data by retreiving it from a function based on the user request. For instance:
{Table.Column} may display everything in that column, {Table.Column|PageName} may be used to format the column.
(this is oversimplified but you get the gist)...I need a default function and modifier handler.
My first thought was to use a prefilter and replace matches with a function call
// Get smarty delimiters
$ldq = preg_quote($smarty->left_delimiter, '~');
$rdq = preg_quote($smarty->right_delimiter, '~');
/* Gather all DatabaseTags */
preg_match_all("~{$ldq}\s*([A-Z].*?)\s*{$rdq}~s", $source_content, $_match);
However this method doesn't address modifiers.
Before I really dig into Smarty hacking, does anyone have ideas on this?
p.s. my head isn't big enough to wrap around this:
preg_match('~^(?' . $this->_num_const_regexp . '|' . $this->_obj_call_regexp . '|' . $this->_var_regexp
. '|\/?' . $this->_reg_obj_regexp . '|\/?' . $this->_func_regexp . ')(' . $this->_mod_regexp . '*))
(?:\s+(.*))?$
~xs', $template_tag, $match)) { |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sat Mar 24, 2007 12:50 am Post subject: |
|
|
Hi Toma.
You mean like an equivalent to __call() ? Maybe instead of filtering, go the whole nine-yards and modify the Smarty code to call user callback as a last-chance before issuing an unrecognized tag error.
But do you really want to do that as functions/modifiers? Should you not rather use {$table.column}? If so, you can always provide a PHP5 overloaded db object that does lazy loading. It would lengthen your example to {$db.table.column} (or maybe {$db->table.column}) which seems like a nice compromise to me.
As for the modifiers, doesn't the normal autoloading already work? Or do you intend to redefine the meaning of modifier syntax here?
Best Regards! |
|
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
|