[pmwiki-users] Conditional Question and PageList Question.

Maxim maxim at smspower.org
Wed Sep 15 04:31:45 CDT 2010


> I am trying to make a pagelist template that uses a conditional that
> will detect whether the pagename has a "-" in it.

Inside a pagelist, you can't use the regular (:if:) conditions in the
way yuo want because they only reference the page being rendered. You
need to test the currently iterated page using the {=$Name} variable.
To do that, you'll need to install additional conditions like
"matchstring" on
http://www.pmwiki.org/wiki/Cookbook/ConditionalMarkupSamples and have
a template like:

(:if matchstring {=$Name} '/-/':)
* %red%[[{=$FullName}]]
(:else:)
* %blue%[[{=$FullName}]]
(:ifend:)

(untested)

> The second thing I am looking for is a way to have a pagelist style
> directive that will list all of the anchors on a page.

Pagelists can't do that (anchors are not pages). You could write a
recipe to do it. Here's a start:

Markup('listanchors', '<split', '/\\(:listanchors:\\)/e', "ListAnchors()");
function ListAnchors()
{
        global $pagename;
        $page = RetrieveAuthPage($pagename, 'read', false);
        preg_match_all('/\[\[(#[^\]]+)]]/m', $page['text'], $anchors);
        foreach($anchors[1] as $anchor) $result .= "*
[[$pagename$anchor|$anchor]]\n";
        return $result;
}

Markup:

(:listanchors:)

If you want it to show the anchors on *other* pages, you'll need to
pass some arguments. I make no guarantees as to the quality of this...



More information about the pmwiki-users mailing list