[dokuwiki] Re: Template Plugin proposal...

  • From: Chris Smith <chris@xxxxxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Tue, 29 Aug 2006 09:35:46 +0100

Terence J. Grant wrote:

What are folks thoughts on moving the template
functions outside of the main codebase and into a "plugin"-- so that
template folks can chip away at the template functions, add new ones
and such... without having to wait for a new dokuwiki stable?

Ideally I think you could keep the admin.php for displaying how to use
the functions(or possibly just link to the api specs) and just have a
single code.php file that you include at the top of your template.
(Like how the "display wiki page" plugin works.)

Thoughts?

You can make functions available to a template via a plugin by placing them in an action plugin outside of the class scope. All action plugins are included prior to the template being included/executed. Or (didn't I mention this before?) you can leave the functions inside the action plugin class scope and have the template trigger (custom) events. Doing things this way neatly avoids having to use extensive function/class/method existence checks. If you fire an event for which there is no handler nothing will happen an no error method with disrupt the user.

e.g.

trigger_event('CUSTOM_TEMPLATE_EVENT',....);

The method you have described doesn't sound extendable. If one file is included, then who knows what version of that file should be there.

As things are template writers can add any funtion they like to their own template by including their own extra files/code. Given the template writer needs to be able to modify their template to do that, ie. they can include any third party files with their template, I am not sure what is gained - unless you anticipate templates being written full of

if (function_exists('custom_template_function')) custom_template_function();
if (class_exists('template_extension_class') && method_exists('template_extension_class', 'method')) { $obj = new template_extension_class; $obj->method(); }


I think this was all pretty well said before in your "plugins that run once" question.


Cheers,

Chris
--
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: