[pmwiki-devel] Link Kludge.
Patrick R. Michaud
pmichaud at pobox.com
Wed Oct 31 13:48:59 CDT 2007
On Wed, Oct 31, 2007 at 02:35:23PM -0400, Stirling Westrup wrote:
> Patrick R. Michaud wrote:
> > On Wed, Oct 31, 2007 at 01:42:55PM -0400, Stirling Westrup wrote:
> >> I have a problem, and there doesn't seem to be a simple way of solving it. The
> >> markup [[Group/]] creates a link to the home page of Group. This is done via
> >> the definition of $DefaultName. What I need, is a way to associate different
> >> home pages with different groups. Its trivial to write up a function that
> >> looks up the home page for a particular group, but the context in which
> >> $DefaultName is expanded doesn't seem to include the information of which
> >> group the home page is for.
> >> [...]
> >
> > Better would be to come up with a $HomePage page variable that
> > returns the home page for any page in a given group.
> >
> > If you can describe the process by which we identify a group's
> > home page, I can describe how to turn it into a page variable.
> > Something like this might even make it into the core, since something
> > like $HomePage would seem to be a _lot_ more flexible than the current
> > $DefaultName mechanism.
>
> Well, currently, I just look up a PTV in the groups GroupHeader page and use
> it if it exists, or I just return the group name as the home name. My function is:
>
> function HomePage($group)
> { global $DefaultGroup;
>
> if( !$group ) $group = $DefaultGroup;
> $gh=MakePageName($group,"GroupHeader");
> $home = PageTextVar($gh,'HomePage');
> if( !$home ) $home = $group;
> return $home;
> }
>
>
> The trouble is, I'd rather not have to hunt for all occurrences of [[Group/]]
> in my wiki and replace them with [[Group/{Group.$HomePage}]] or something...
Yes, but you could easily set $PagePathFmt to be
$PagePathFmt = array('{$Group}.$1', '$1.{$HomePage}');
and then MakePageName will use the $HomePage page variable instead
of $DefaultPage when computing the result of "Group/" or "Group."
So would other places that want to treat a page reference as a
link to a group's home page.
Also, I think the above function is better written as:
function HomePage($pagename) {
$group = PageVar($pagename, '$Group');
$home = PageTextVar("$group.GroupHeader", 'HomePage');
if (!$home) $home = $group;
return $home;
}
Then it can be turned into a page variable with
$FmtPV['$HomePage'] = 'HomePage($pn)';
This, combined with setting $PagePathFmt as given above, should
give you what you want.
Pm
More information about the pmwiki-devel
mailing list