[pmwiki-users] New Hierarchical Groups Recipe...
Kathryn Andersen
kat_lists at katspace.homelinux.org
Thu Feb 1 22:00:01 CST 2007
On Thu, Feb 01, 2007 at 09:12:12PM -0500, The Editor wrote:
> On 2/1/07, Kathryn Andersen <kat_lists at katspace.homelinux.org> wrote:
>
> > The $FmyPV variable needs to be defined as a call to a function which
> > takes a group name or a page name as one of the arguments; that means it
> > is dynamic and will be recalculated appropriately, and will work with
> > pagelists.
>
> Ok, that makes sense. But how do you get it to take a group name?
> something like
>
> function hgsubgroup($x=$Group) {
>
> Pardon the sloppy notation, just trying to get the idea..
>
> It's also a bit tricky. As it is, Hg generates the appropriate number
> of pagevars dynamically based on the number of hyphens in the group
> name. In a pagelist, theoretically, that number would be variable
> depending on the individual pages. Would that mean each variable
> would have to have a separate line calling the function, something
> like
>
> FmtPv [$g1] = ' hgsubgroup($x={$group}, level=1) ';
> FmtPv [$g2] = ' hgsubgroup($x={$group}, level=2) ';
>
> This would mean, it would only work to a predefined number of
> levels--say 5 or 10, rather than unlimited. Am I correct?
Yes, but you could make the limit not hardcoded, if one goes through a
loop. I've been having a go, and the following is what I've come up
with. It seems to work.
SDV($hgseparator,'-'); # as before
SDV($hgmaxlevels,10);
// counts of group-levels and name-levels
$FmtPV['$g0'] = 'HgCountNameParts($group)';
$FmtPV['$n0'] = 'HgCountNameParts($name)';
// create up to $hgmaxlevels of variables
for ($i=0; $i < $hgmaxlevels; $i++)
{
$hg = "g" . ($i + 1);
$hn = "n" . ($i + 1);
$FmtPV['$' . $hg] = 'HgSplitName($group, ' . $i . ')';
$FmtPV['$' . $hn] = 'HgSplitName($name, ' . $i . ')';
}
// split a name on $hgseparator, and return the count of parts
function HgCountNameParts($name) {
global $hgseparator;
$parts = explode($hgseparator, $name);
return count($parts);
}
// split a name on $hgseparator, and return the requested bit
function HgSplitName($name, $ind) {
global $hgseparator;
$parts = explode($hgseparator, $name);
if ($ind < 0 || $ind >= count($parts))
{
return '';
}
else
{
return $parts[$ind];
}
}
Using this, I've been able to make some nifty pagelist templates:
!!!fmt=#hgtitle
List of groups (showing title), giving nested hierarchical groups;
assumes that list=group
[@
[[#hgtitle]]
(:if !equal "{<$g1}" "{=$g1}":)
*[[{=$Group}.|+]]
(:if ( equal "{<$g1}" "{=$g1}" and equal "{=$g1}" "{*$g1}" ) :)
**[[{=$Group}.|+]]
(:ifend:)
[[#hgtitleend]]
@]
----
!!!fmt=#hgtitle3
Three-level list of groups (showing title), giving nested hierarchical
groups; assumes that list=group
[@
[[#hgtitle3]]
(:if ( !equal "{<$g1}" "{=$g1}" and equal "{=$g0}" "1" ):)
*[[{=$Group}.|+]]
(:if ( ( equal "{<$g1}" "{=$g1}" and equal "{=$g1}" "{*$g1}" ) and
equal "{=$g0}" "2" ) :)
**[[{=$Group}.|+]]
(:if ( equal "{*$g1}" "{=$g1}" and ( equal "{=$g2}" "{*$g2}" and !equal
"{=$g3}" "" ) ) :)
***[[{=$Group}.|+]]
(:ifend:)
[[#hgtitle3end]]
@]
The above templates assume that the following $SearchPatterns is defined
in one's config.php; this makes it easier/quicker to make pagelists that
consist only of groups, which is often what one wants to do in, say, a
SideBar.
# make a group-only Group.Group search pattern
$SearchPatterns['group'][] = '/([-\w]+)\.\1$|\.' . "$DefaultName" . '$/';
Kathryn Andersen
--
_--_|\ | Kathryn Andersen <http://www.katspace.com>
/ \ |
\_.--.*/ | GenFicCrit mailing list <http://www.katspace.com/gen_fic_crit/>
v |
------------| Melbourne -> Victoria -> Australia -> Southern Hemisphere
Maranatha! | -> Earth -> Sol -> Milky Way Galaxy -> Universe
More information about the pmwiki-users
mailing list