Menu

#2 Ability to register callback functions.

open
Maxx
5
2003-06-05
2003-05-20
Sjon
No

Hi.

I've made my own templating function library in php (who
hasn't), and added besides the standard replacement
stuff also a way to incorporate so called tags inside
templates, wich can be assigned a handler.
Example:
// the tag wich can be put inside a template
<tag:random min="100" max="999" />

// registering a handler with a tag
stpl_register_tag
(STPL_FETCH_EVENT, 'random', 'stpl_tag_random');

// example function
function stpl_tag_random ($params) {
$min = (isset($params['min']) ? $params['min'] : 0);
$max = (isset($params['max']) ? $params['max'] :
mt_getrandmax());
return mt_rand($min, $max);
}

the STPL_FETCH_EVENT is one of three events that
occur. In order:
STPL_LOAD_EVENT: when the template get's read
from disk
STPL_PARSE_EVENT: when the template get's parsed
(variable substitution)
STPL_FETCH_EVENT: when the parsed content get's
fetched for display/storage

Now, I know the event stuff may not really make sense
with this extension (maybe the first two do), but I would
love to see something like this incorporated into this
extension.
I'm no C programmer, so I can't be of much use in that
field, but I would love to help. I think one additional
function and two ini entries (tag_start and tag_end)
would be all that's needed. Maybe even add a few
predefined tag handlers (like above random, date,
include), etc.

If you've got any questions, let me know.

Regards, Sjon.

Discussion

  • Sjon

    Sjon - 2003-06-05
    • assigned_to: nobody --> su1d
     
  • Sjon

    Sjon - 2003-06-05

    Logged In: YES
    user_id=63959

    Maxx, any thoughts ???

     
  • davojan

    davojan - 2006-09-17

    Logged In: YES
    user_id=1229151

    I want this feature very much too. Pleaaaasee! :)

     

Log in to post a comment.