[pmwiki-users] Re: Getting a list of the cateogories that thecurrent page belongs to?

John Rankin john.rankin at affinity.co.nz
Wed Oct 5 17:05:21 CDT 2005


On Wednesday, 5 October 2005 8:52 PM, chr at home.se wrote:
>On 5 Oct 2005, John Rankin wrote:
>> You might try something like this in a GroupHeader page:
>> 
>> (:iscategorised:)
>> 
>> With the following rule:
>> 
>> Markup('iscategorised','>nl1','/\(:iscategorised:\)(.*)/se',
>>     "IsCategorised(\$pagename,PSS('$1')).PSS('$1')");
>> 
>> function IsCategorised($pagename,$text) {
>>     preg_match_all('/(\\[\\[!.*?\\]\\])/',$text,$m);
>>     if (count($m[0]) == 0) return 'Please categorise this page.';
>>     return 'Categories: '.implode(', ',$m[1]);
>> }
>Very neat. The markup works in normal pages and the group
>header.
>
>When I tried it in the sidebar, it didn't work however. Do you have any 
>idea why?
>
The above formulation relies on having the full text of the page, after
includes. The GroupHeader gets prepended to the page text before the 
page is processed, so when the above rule is in a GroupHeader, 'it just
works'.

However, when the directive is in a SideBar, it will only have the text
of the SideBar page to work on, not the page itself. Assuming the 
SideBar is uncategorised, it will always return 'Please categorise...'.

AFAIK the only way to have a SideBar take account of page contents
is to do what you have done and read it. This means any [[!category]]
markup in include directives will be omitted. That may not be a bad
thing: I think (but haven't tested) that if PageA includes PageB
and PageB contains [[!category x]], then on page CategoryX we will
see PageB but not PageA. So this may not be the big drawback you
suggest, but it /is/ confusing -- in the PageA PageB CategoryX
example, a reader of PageA will be invited to 'Please categorise 
this page' but to all intents and purposes it's [[!category x]].
So our reader clicks on the category x link and behold! no PageA.
Confusion all round.

Assuming the above thought experiment is valid, a possible solution
would be to omit [[!.*?]] from included pages, but this seems a bit
arbitrary and an attempt to second-guess the author's intent.

So I think the formulation of the solution given above should
arguably run before include directives are processed. And I don't 
know the best way to handle categories on included pages.

Kind regards
-- 
JR
--
John Rankin






More information about the pmwiki-users mailing list