[WM] sitemap grep attribute
Justin Mason
jm.jmason.org
Sun Jan 21 17:09:48 GMT 2001
alex canady said:
> i think this may be possible with the grep attribute
> of the sitemap function [...]
> what i can't figure out is where the $_ is in
> relationship to the overall processing of the sitemap
> rendering code - confusing i know. i need to know
> what i can compare $_ (the current content name) to ??
>
> if the node is for the current content ($_) then draw
> it.
> if the node is a parent for the current content then
> draw the node.
> if the node is a top level node then draw the node.
> but all i have to work with is $_ (the content name,
> not the node).
> is this the right logic or am i just going down the
> wrong path?
Hmm, not sure...
The "current content item's name", as mentioned in the grep documentation,
is not the name of the current *page* -- it's the name of the content item
that's being looked at in the sitemap.
The "grep" code is evaluated once for every node in the sitemap, and $_ is
the name of that node; you can then decide to display/not display it.
Problem is, at the moment, the sitemap is only computed once... I hadn't
anticipated what you're planning to do :(
What you want is quite similar to the "breadcrumbs" concept, check out the
<breadcrumbs> tag for details on that.
Here's how to do it. First, generate a full sitemap, then *not use it*;
instead you just use the knowledge of the site layout from your own code.
When generating the page, include your own content item which does
something like this, in Perl:
<{perlout
# get the "main" content item on the page (A)
my $cont = get_content_object("__MainContentName");
# get the top-level "root" content item (B)
my $root = $cont->{main}->getmapper()->get_root();
my @family = ($cont);
while (1) {
$cont = $cont->get_up_content();
if ($cont == $root) { last; }
unshift (@family, $cont);
}
# now @family contains the list of this node, and the parent nodes,
# like: ($parent1, $parent2, $thisnode)
my @toplevels = $root->get_sorted_kids();
# now @toplevels contains the list of all top-level nodes (ie.
# nodes directly underneath the "root node".
# now display them. Links and good-looking HTML are left
# as an exercise for the reader ;)
#
my $topfamily = $family[0];
foreach my $node (@toplevels) {
print "+ <em>$node</em><br>\n";
if ($node == $topfamily) {
foreach my $famnode (@family) {
print "- <em>$node</em><br>\n";
}
}
}
}>
There's a few undocumented things in there, I must make those visible
in the Perl code library to make it easier to do this stuff. Here's
what they do.
(A): "__MainContentName" is a magic content item; it's always set to the
name of the "main" content item on the page. This is worked out as the
last non-generated content item displayed, which has "map=true" set.
(B): There's currently no decent API to get the root content item from
Perl code, so I've used the one I use internally. Sorry about this; both
of these will get proper APIs in the next version. :)
Another key point: when you refer to this content item you've just
defined, be sure to use a $[deferred_reference], otherwise it may be
expanded before __MainContentName is set.
In fact, this functionality sounds like a good feature for a new tag.
What do you think?
BTW I know the documentation is pretty skimpy. If you run into particular
bits that are definitely poorly docced, send in suggestions/requests for
more doc and I'll know exactly which bits need work...
(Also: did the previous problem, with the .../*.txt not finding certain
files, work out OK, or is it still an issue?)
--j.
More information about the Webmake-talk
mailing list