[pmwiki-users] The Template Shuffle

David Spitzley dspitzle at wash.k12.mi.us
Fri Apr 15 09:47:07 CDT 2005


<grovel>I am not worthy!</grovel>
:)

Seriously, that is really cool.  I'll see what I can do about
developing Cookbookery on this subject once I've tested that it all
works.  



David

>>> "Patrick R. Michaud" <pmichaud at pobox.com> 04/14/05 10:29 PM >>>
On Thu, Apr 14, 2005 at 09:16:04PM -0400, David Spitzley wrote:
> Ok, I'm looking to do something with templates that may not be
doable,
> but I thought I'd ask.  My wiki has a page called MichiganCounties,
> which has one link off of it to each county in the state; the
majority
> of them do not currently have pages, and through PM's kind advice, I
was
> able to set up MichiganCounties.php so that all of the links off of
that
> page use CountyTemplate as the source template.  That's spiffy.
> 
> The trick now is that each County page is going to have two sets of
> links: one set points to pages for municipalities in the county,
while
> the other set points to pages for school districts in the county. 
So,
> the question is, can I somehow set up the CountyTemplate page so
that
> the links in the municipalities section use MunicipalityTemplate and
the
> school districts use DistrictTemplate?  I'm inclined to think not
given
> how the trick in MichiganCounties.php is set up, but I figured I
might
> as well ask.  

...some people are *never* satisfied!  :-) :-) :-)

But, since you asked, and since I like a challenge, here goes an
idea.  I haven't tested any of this code -- I just want to see if
it's along the lines of what you're looking for...

In config.php:

    # change the link format for creating new pages
    $LinkPageCreateFmt = "<a class='createlinktext'
href='\$PageUrl?action=edit\$LinkTemplate'>\$LinkText</a><a
class='createlink'
href='\$PageUrl?action=edit\$LinkTemplate'>\$LinkText</a>";
    
    # default is no template
    $LinkTemplate = '';

    # the (:template Group.PageName:) markup causes any create page 
    # links that follow to use Group.PageName as the template
    Markup('template', 'directives',
      '/\\(:template\\s(\\S+)\\s*:\\)/e',
      "PZZ(\$GLOBALS['LinkTemplate'] = '&amp;template=$1')");

Okay, in the MichiganCounties page you can add the directive
(:template Content.CountyTemplate:).  This will cause all new page
links that come after the directive to use Content.CountyTemplate
as the default.

In the CountyTemplate page you'll add
(:template Content.MunicipalityTemplate:) before the section
with the municipality links and (:template Content.DistrictTemplate:)
before the section with the school district links.  This changes
the new page links in each section to the corresponding templates.

Of course, I've used (:template ...:) here to show generally how
this works.  But you might not want people to see (and be confused
by) the (:template ...:) directives in the middle of the markup.
So, you could key the setting of the template off of something else.  
For example, if you know that the sections will always begin with 
"!!!Municipalities" and "!!!School Districts" in the markup, you
can key the changes from those:

   # "!!!School Districts" switches template to
Content.DistrictTemplate
   Markup("schooldistricts", "directives",
     "/^!!!School Districts/e",
     "'$0'.PZZ(\$GLOBALS['LinkTemplate'] =
        '&amp;template=Content.DistrictTemplate')");

   # "!!!Municipalities" switches template to
Content.MunicipalityTemplate
   Markup("municipalities", "directives",
     "/^!!!Municipalities/e",
     "'$0'.PZZ(\$GLOBALS['LinkTemplate'] =
        '&amp;template=Content.MunicipalityTemplate')");

Note that the "!!!School Districts" markup still gets processed to
produce an <h3> heading (it's left there via the '$0' in the 
replacement string) -- but now that specific heading also has the
side effect of changing the edit template for any new page links
that follow it.

Anyway, hope this helps, or at least points in the general direction
of how this could be solved.

Pm



More information about the pmwiki-users mailing list