[Pmwiki-users] PmWiki Templates revisited

niall b durham nbd3355 at sci.tamucc.edu
Wed Jun 25 10:52:05 CDT 2003


Hello all,

I'm working on a new version of single-file template(s) for PmWiki and
seek some help/feedback/ideas so I don't end up with an overly-complex
and unnecesary system.  Well, any more complex and unecessary than it
already is.

In case it isn't obvious, this e-mail is long.  Patience is probably
required. :)

Background: 

Many months ago I wanted an easy way to just place the body of a 
PmWiki page inside of a site-wide/group-specifc HTML page template.  
The idea was to allow someone who didn't know PHP (but knows HTML) 
create a webpage template (with style sheets, etc.) within which 
PmWiki pages would be included.

In case my description sucks, you can see an example of it here:
http://www.doctorducks.com/ 

The site is comprised of a template page which has the main HTML and
includes a few other files via SHTML-like syntax.  There is a script
which parses this template each time a page is called, interprets the
bastardized SHTML syntax and splits it in two pieces (header and
footer).

Right after I first mentioned it on this list, Pat pointed out it would
be better to have PHP do all the file including and variable 
interpolation.  Not only would it be much faster, it allows one to 
include arbitrary PHP syntax into the template--much more powerful.

I took those ideas to heart but used what we currently had because it
worked and I had to spend time on other things.

The present:

Now I'm at the point where I'm revisiting things and working on a new
implementation of this (with the suggested ideas) using the latest 
release of PmWiki.

Because of the new syntax allowed in the PrintFmt() function, its
trivial to have PmWiki include another file as the header and/or
footer.  I dump the old STHML-like syntax and just use PHP inside the
template exclusively except for a simple marker to denote where in the
template the PmWiki page body should go.

But I only want to require the template author to deal with a single
file per unique template (just like the old system)...  By adding 
another action to my local.php script, I parse any template files in 
the template directory and split them into separate header/footer 
files.

Once this action has been done, its easy to search for the
existence of any (already-processed) template files whenever 
action=browse.  If one exists, I'll include it as the header/footer
of the returned PmWiki page.

So the current approach has these steps: 

(1) The template author makes/modifies HTML/PHP template page(s).
(2) They upload the template(s) to the site.
(3) They run the action=template once to process all the templates.
(4) Any browsing done thereafter will place the PmWiki text body 
    into the proper template (if any).

There's a problem I'm running into, however.  We like to use some 
global variables make sure that all our links are properly prefixed.
E.g.:

    <a href="<?php echo $ScriptUrl; ?>/Group/Pagename">...</a> 

Its not pretty, but it works :).  However, since the includes 
are occurring inside of the PrintFmt function, none of the global 
variables are available unless explicitly brought into scope.  E.g.:

    <?php global $ScriptUrl; ?>

This has to be done in *both* the header and footer files. 

I don't like the idea of requiring the template author to include 
this global scope PHP excerpt in the template file *twice* (at the 
start of the file as well as after the marker denoting the placement 
of the PmWiki page body).  Of course, this assumes that the template
author wants to use any global variable(s) in both the header and the
footer.

So I came up with the bright idea of writing a "magic" step 
(optional) during the template-processing (only used when the 
action=template is called) which would parse the PHP code contained 
within the template and automatically add the necesary code:

    <?php global $VarName1, ..., $VarNameN; ?>

When required (if it "determines" that global variables are being
called--I'm not going to describe my heuristic right here for
berevity, but I'm sure it has some holes in it).  

So I have it properly pulling any PHP code out of the template file
(well, to some extent--the regexp works but it crashes/timesout on a 
block of PHP code the size of PmWiki :), but there's another problem.

If I'm including other files (<?php include("foo.php"); ?>) inside my 
template then their code won't be included when I'm doing this 
pre-processing of the template file (step 3).  So, now I'm looking at 
parsing those files when I process the templates in order to make sure 
I can check them for any variable references before generating the 
global scope syntax.

It is at this point I have to stop and ask myself if I'm making things
needlessly complicated.  This, dear, patient reader, is where you come
in.

Ideas?  Direction?  Insight?

Thanks for bearing with me,

Niall
-- 
nbd3355 at sci.tamucc.edu
http://www.cbi.tamucc.edu/~durham/




More information about the pmwiki-users mailing list