[pmwiki-users] Pagelists, adjunct data pages & variable sort orders

Patrick R. Michaud pmichaud at pobox.com
Tue Oct 17 01:55:07 CDT 2006

On Mon, Oct 16, 2006 at 10:04:53PM -0400, Crisses wrote:
> On Oct 16, 2006, at 7:26 PM, Patrick R. Michaud wrote:
> >FWIW, I think that at some point we have to stop asking the PmWiki
> >markup syntax to solve every conceivable problem, and just say
> >"okay, this particular feature needs a custom PHP function to
> >do its work".  I'm not necessarily saying that we've reached that
> >point here, but for some things markup is a terribly inefficient way
> >of getting to our results.
> Oh, I don't believe in scope creep on this.  I just have a hard time  
> saying "yes you can spit out pagelist groups based on arbitrary data"  
> while also saying "but the groupings won't work as expected because  
> you can't sort them".  

I'm having some difficulty with this remark... it's never been my
intent or expectation that the current set of pagelist builtins
would be sufficient for grouping things based on arbitrary data.
In fact, I think I've been consistently been making the point
that using pagelist templates for grouping is probably not
the ideal way for accomplishing grouping, and that it's far better
to be defining custom page variables for grouping than trying to
manage it all in markup.  (Example to follow.)

> The basepage format options have worked well,  
> but I consider that either a missing feature or bug, because I try to  
> group the output to eliminate dupes and it fails miserably due to the  
> unsorted nature of the pagelist being handled.  

It's possibly a missing feature.  But it was never my intent or
expectation to be using $BasePage markups as a way to relate page
text variables among multiple pages, or that we would ever find 
ourselves attempting to order/group one set of pagenames based 
on the attributes or contents of an entirely different (but 
somehow related) set.

> If I can handle it in  
> a pmwiki-hook ratified manner, great.  If I have to try to hack  
> pmwiki without knowing the hooks, it's going to be *awful*.

Thinking about it a bit more, it's clear that page variables
are (or should be) the general pmwiki hook for doing custom things
with attributes and properties of pages, in whatever form.

In fact, here's *another* way to handle the sort/group/display 
problem by defining custom page variables that have exactly what 
you want, and without needing to define any custom sort features
for (:pagelist:).

Let's define $Year, $Work, and $WAuthor page variables for
every page, such that the values of $Year, $Work, and $WAuthor for any 
page Group.XYZ are always the $:Year, $:Work, and $:WAuthor page 
text variable from Group.XYZ's corresponding Data-* page.   In
other words, {$Year} for any page will always act as if one
had specified {Data-{$BaseName}$:Year}.

Here are the definitions:

    $FmtPV['$Year'] = 
      "PageTextVar('Data-'.PageVar(\$pn, '\$BaseName'), '$:Year')";

    $FmtPV['$Work'] =
      "PageTextVar('Data-'.PageVar(\$pn, '\$BaseName'), '$:Work')";

    $FmtPV['$WAuthor'] =
      "PageTextVar('Data-'.PageVar(\$pn, '\$BaseName'), '$:WAuthor')";

Okay, so what does this buy us?  Well, the value of {$Year} for any
page will always be the value of {$:Year} from its corresponding
Data- page.  Thus {Simile.Steinbeck$Year} always returns the 
value of {Data-Simile.Steinbeck$Year}.  What's more, this works
even if the current page is in Data-Simile -- i.e., the value of
{Data-Simile.Steinbeck$Year} is the same as 
{Data-Simile.Steinbeck$:Year}.  (The first is a page variable, 
the second is a page text variable.)

So, what we've done is to move all of the issues of relating
pages to Data- pages out of the pagelist template and into 
some relatively simple page variable definitions.  With this
in place, our pagelist directives then look like:

    (:pagelist group=Simile order=$Year,$Work,$WAuthor:)
    (:pagelist group=Data-Simile order=$Year,$Work,$WAuthor:)

The specification of order=$Year,$Work,$WAuthor (page variables)
means that we will sort the list of pages based on the
$:Year, $:Work, and $:WAuthor page text variables of the
corresponding pages in the Data-Simile group.

Note that we also don't have to worry about whether the 
pagelist is running through the pages of the Simile or 
Data-Simile groups, because our custom page variables 
always map the pagename into the Data- form of the group.

This also greatly simplifies the pagelist template, because 
we can now write:

    (:if ! equal {<$Year} {=$Year}:)
    !! {=$Year}

Again, the '$Year' page variable is taking care of the
details of obtaining $:Year from the correct Data-{$BaseName}
page, instead of trying to force the evaluation through the


More information about the pmwiki-users mailing list