Summary: Talk page for MoreCustomPageVariables.
Maintainer: Petko
Users: +2 (View / Edit)

This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.

Marcus Denning - 20170815 07:45 - This is the best place I can think of to post this, because it is too good to keep to myself. A huge thanks to Petko!
Here was my original question:
I have been searching and have not seen this issue addressed yet.
I guess I do not understand enough about the core processing of variables from the page and group headers.

The purpose is to have a an anchor [[#top]] in the groupheader page and {$top} or {$:top} variable with the value
[[#top | %color=#0000ff%''top''%%]]
in it contained within the groupheader page so that I do not have to continually add
[[#top]][[#top | %color=#0000ff%''top''%%]]
at the beginning of every page and still every page can just use a {$top} or {$:top} variable in it.
I keep getting errors on previews to test a config.php addition of a custom page variable.
I want to implement something in a groupheader like this:
$FmtPV['$top'] = "[[#top | %color=#0000ff%''top''%%]]";
And formatting it with escaped characters still errors out like this:
$FmtPV['$top'] = "\[\[#top | %color=#0000ff%\'\'top\'\'%%\]\]";
It keeps giving errors on an unexpected '[' in the pmwiki.php module. Do I need to resort to unicode to push this through?

uh, help please?

Don't use a Page variable for this, use a markup rule, and a css style. Page variables are for page-dependent variables, that is, something specific for one page and different for another page, eg the title or the URL.

Here is your custom markup:


This means: a rule uniquely named "#top" ,
   before links get to be processed,
   when in the text we find (:top:) ,
   replace it with [[#top|top]] .

Here is your custom CSS to add in pub/css/local.css:

   a[href="#top"] {color: blue; font-style: italic;} 

This means: when a link with the reference "#top" is found, make it blue and italic. This way, no need for %blue%''...''%% (#0000ff=blue)

That's it.

With the custom style, you may find that writing [[#top|top]] is actually not that much harder than (:top:) or {*$:Top} , and I will agree.

Finally, I wouldn't place the [[#top]] anchor in a GroupHeader for every group, instead I'd place <a id="top"></a> it in the skin template.


Follow-up: If you must for some reason create a page variable with a static text string, you need to enclose it in two layers of quotes:
$FmtPV['$top'] = "\"[[#top | %color=#0000ff%''top''%%]]\"";
This string is evaluated by PHP. It is very highly recommended to NOT place here some user-supplied text, either from the wiki text or from the $_REQUEST/$_GET/$_POST/$_COOKIE variables, or you'll easily open critical security holes. For the latter, see HttpVariables. --Petko August 15, 2017, at 10:06 AM

Hi, is there a way to make a part of page name a variable in local config file. Some like with

{(substr "PmWiki" 0 1)}


Thanks, Teukka

Sure. Use something like this after any scripts and recipes that you include:
# Get the group and page name
$pagename = ResolvePageName($pagename);
$name = PageVar($pagename, '$Name');
$my_special_config_variable = substr($name, 0, 1);
If you wish to use such a value as a custom PageVariable (in wiki pages), use this instead:
$FmtPV['$Substr01'] = 'substr($name, 0, 1)';
and use in the page {*$Substr01}. The variables $name and $group will be replaced on runtime. This also works with PageLists, use {=$Substr01} inside a pagelist template. --Petko October 11, 2007, at 09:48 AM

Thank You so much. This was great help for me.

I have a template with an image I want to modify. Specifically, in the template file I have <img src="{ $ CustomImage}">. I want to modify this variable in the wiki edit mode so that I can set a unique "splash" image for each page. Is there anything like:

{SetVar CustomImage test.jpg}

that I can include in the bottom of my wiki code.


I think many don't understand wiki templates. Consider the following:

       <!--wiki:{$Group}-{$Name}.Logo {$Group}.Logo {$SiteGroup}.Logo-->

Inside of a page template this will look for Group-Name.Logo first (where Group is the Group and Name is the Name), then Group.Logo (for the current Group), then ultimately fall back to the Site.Logo file. These turn into includes of the page... so to have a custom Logo per page, just define Group-Name.Logo files for each page.

I have a question. Is it possible to store a variable from a cookbook using FmtPV and call it in the wiki? It works perfectly when I store a variable in config.php, but it doesnt when I write it in a cookbook. I suppose I should be clearly specifying in which php cookbook the variable is stored. I wrote :

 $FmtPV['$TestVariable'] = "'SelectQuery is outputting'";  

in the selectquery.php cookbook

and in a page using this cookbook, i tried to call it using {$TestVariable}. But got no result.

Thanks for the support... Chris

In your script, place global $FmtPV; before defining $FmtPV['$TestVariable']. Also make sure you include your cookbook script from config.php or from Group.Page.php. --Petko August 20, 2009, at 04:34 PM

Note about changing variables

Please remember that changing core page text variables will affect your wiki. If you change the following page text variable this will affect your RecentChanges pages:

$FmtPV['$CurrentTime'] = 'date("H:i:s")'; // 14:29:32

I would recommend something like:

$FmtPV['$NowTime'] = 'date("H:i:s")'; // 14:29:32

Otherwise the date may not show in RecentChanges pages.

Talk page for the MoreCustomPageVariables recipe (users).