You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jspwiki.apache.org by Bob Paige <bo...@gmail.com> on 2009/03/03 19:45:12 UTC
capturing output of a plugin in a page variable
We use a naming convention on pages in our wiki, where each page name is
prefixed with the project name and suffixed with the page type. Project
pages are just suffixed with the word 'Project'. It has some limitations,
but it works for us :)
So I created a simple plugin that, given a page name, strips the prefix and
suffix as appropriate. I (confusingly) called it 'PageName'. It works like
this:
[{PageName}]
If the name of the page is 'My Project Section 5 Specification', the macro
strips off the 'My Project' (because there is a page called 'My Project' it
assumes that is the prefix) and the word 'Specification' because that is the
last word in the page name (page types are always one word).
Is it possible to capture the output of a macro in a page variable, as
described in (
http://lwa08.informatik.uni-wuerzburg.de/Wiki.jsp?page=WikiVariables)?
[{SET name='foo'}]
[{$name}]
returns 'foo'
What I want is:
[{SET name='[{PageName}]'}]
[{$name}]
Unfortunately, all I get is 'PageName'.
--
Bobman
Re: capturing output of a plugin in a page variable
Posted by Bob Paige <bo...@gmail.com>.
Great! Works like a charm.
I think I'll add this 'var=' behavior to all my plugins!
--
Bobman
On Tue, Mar 3, 2009 at 2:50 PM, Janne Jalkanen <Ja...@ecyrd.com>wrote:
>
>
> D'oh. Now I understood what you meant :-)
>
> There are two techniques you could use.
>
> 1) Create a custom PageFilter which does a wikiContext.setVariable("name",
> extractRealName(wikiContext.getPage().getName()) in preTranslate(). This
> effectively creates a "{$name}" variable on every single page.
>
> 2) Create a plugin which does the same. So you could say
>
> [{PageName var="name"}]
>
> and the PageName plugin would then put the page name into the "name"
> variable. See the Counter plugin for an example how this can be done.
>
> /Janne
>
>
> On Mar 3, 2009, at 21:46 , Janne Jalkanen wrote:
>
>
>>> What I want is:
>>>
>>> [{SET name='[{PageName}]'}]
>>> [{$name}]
>>>
>>> Unfortunately, all I get is 'PageName'.
>>>
>>
>> Almost!
>>
>> [{SET name='{$PageName}'}]
>> [{$name}]
>>
>> The reason is that [ ] is a "special" sequence. Then there are many kinds
>> of special sequences:
>>
>> {$name} for variable
>> {plugin} for plugin
>> PageName for page names.
>>
>> Granted, this is slightly illogical.
>>
>> /Janne
>>
>
>
Re: capturing output of a plugin in a page variable
Posted by Janne Jalkanen <Ja...@ecyrd.com>.
D'oh. Now I understood what you meant :-)
There are two techniques you could use.
1) Create a custom PageFilter which does a
wikiContext.setVariable("name",
extractRealName(wikiContext.getPage().getName()) in preTranslate().
This effectively creates a "{$name}" variable on every single page.
2) Create a plugin which does the same. So you could say
[{PageName var="name"}]
and the PageName plugin would then put the page name into the "name"
variable. See the Counter plugin for an example how this can be done.
/Janne
On Mar 3, 2009, at 21:46 , Janne Jalkanen wrote:
>>
>> What I want is:
>>
>> [{SET name='[{PageName}]'}]
>> [{$name}]
>>
>> Unfortunately, all I get is 'PageName'.
>
> Almost!
>
> [{SET name='{$PageName}'}]
> [{$name}]
>
> The reason is that [ ] is a "special" sequence. Then there are many
> kinds of special sequences:
>
> {$name} for variable
> {plugin} for plugin
> PageName for page names.
>
> Granted, this is slightly illogical.
>
> /Janne
Re: capturing output of a plugin in a page variable
Posted by Janne Jalkanen <Ja...@ecyrd.com>.
>
> What I want is:
>
> [{SET name='[{PageName}]'}]
> [{$name}]
>
> Unfortunately, all I get is 'PageName'.
Almost!
[{SET name='{$PageName}'}]
[{$name}]
The reason is that [ ] is a "special" sequence. Then there are many
kinds of special sequences:
{$name} for variable
{plugin} for plugin
PageName for page names.
Granted, this is slightly illogical.
/Janne