Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Smarty and wordpress/flatpress filters... need advice

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
NoWhereMan
Smarty Rookie


Joined: 14 Feb 2006
Posts: 15

PostPosted: Wed Feb 14, 2007 1:17 pm    Post subject: Smarty and wordpress/flatpress filters... need advice Reply with quote

Well, FlatPress is the project I've been working on; it uses Smarty, but since now it never used the real power of Smarty, and its use was limited to pass some bunch of variables in when some block tags existed.

Now I have a little problem I can't come up with a good solution so I ask for someone else's advice (as on my ML nobody seems to have nor time nor will to answer :S)

Well, as you may know, wordpress uses a system based on an array an subsequent call of several functions for each element of that array; every field of the associative array is a "plugin hook".

add_filter('plugin_hook', 'name_of_a_function');

You then apply filters calling

$var1 = apply_filters('plugin_hook', $var1, ...) // you may have more than one var


now, I used to have this

{entry}{/entry} block which applied all of the filters on some variable and then make it available in the block body; for instance it did (not really this way, I use an array in the actual code, but nevermind)

$content = apply_filters('the_content', $content);

$smarty->assign('content', $content);

and to display the value you would use

{$content}


Now, parsing/applying filters every time a {entry} block is found is something expensive and sometimes not needed; so I decided to make this on demand, using a modifier called tag

function tag($value, $hook);

{$content|tag:the_content}

Which I find very cool and nice looking.

The problem is that I have this hook called the_permalink which expects a post $id as a SECOND parameter Sad (the first parameter must be a formatting string or empty string)

So I can't do a {$id|tag:the_permalink} i should rather do a {''|tag:the_permalink:$id}

which I found quite ugly, as I doesn't have a great semantics, you know...

So I could rather have a functional tag

{tag hook=the_permalink var=$id}

but this way the problem is the same, how can I know if var is the second (null string) or the third parameter (id) (we must keep in mind tag would become a general purpose function wrapper for apply_filters as |tag should be a general purpose modifier wrapper).

So how can I work this out?

I wouldn't want to add several {function} tags as if I made it for {the_permalink} I should make it for {the_content} as well, or I'd loose symmetry, and this would be quite ugly, IMO.

Any advice?

Thank you ssooooo much Smile
_________________
-- FlatPress Flat-file based blog, Smarty-powered
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
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