Page text variables are string variables created in the wiki text of a page, and can be automatically made available for inclusion in other pages. In the default installation, PageTextVariables can only have a name containing basic Latin/Roman (ASCII) letters, digits, dash and underscore (meaning regular PTVs don't have accented characters). This is a limitation for international wikis (experimental recipe for international PTV : Cookbook:InternationalPTVs).
Defining Page Text Variables
There are three ways to define automated Page Text Variables (more patterns can be defined if needed) :
use a definition list - the normal pmwiki markup for a definition list will create a page text variable
Example definition list:
:Name: Crisses
"{$:Name}"
Name
Crisses
"Crisses"
This creates a new variable that can be accessed by {$:Name} (becomes: "Crisses") in the page.
use a simple colon delimiter in normal text
Example colon delimited:
Address: 1313 Mockingbird Lane
"{$:Address}"
Address: 1313 Mockingbird Lane
"1313 Mockingbird Lane"
This creates the {$:Address} variable (variable markup becomes: "1313 Mockingbird Lane") in the page.
hidden directive form - PmWiki markup that doesn't render on the page, but defines the variable
Example directive:
(:Country: Transylvania :)
"{$:Country}"
"Transylvania "
This creates the {$:Country} variable (variable markup becomes: "Transylvania ") in the page.
Default values for unset or empty Page Text Variables
If a page text variable is not defined in a page, or if the current visitor doesn't have read permissions for the page containing the variable definition, then the markup to access the variable like {$:Country} will return an empty string.
An administrator can define default values for such cases (PmWiki 2.2.121+). The following arrays can be defined in local/config.php:
$DefaultEmptyPageTextVars = array(
'SpecificVariable' => 'SpecificVariable is set, but empty',
'*' => '(empty)',
);
In the above examples, {$:SpecificVariable} or {OtherPage$:SpecificVariable} will output the value defined:
in $DefaultUnsetPageTextVars if the variable is not defined in the page text, or if the user doesn't have read permissions for OtherPage
in $DefaultEmptyPageTextVars if the user has read permissions, and the variable is defined but empty, for example (:SpecificVariable::).
The patterns are processed in order, and the first matching pattern assigns the value to the variable. The asterisk * matches any string, in the above examples an undefined variable that doesn't match 'SpecificVariable' or '*PartialMatch*' will output '(unset)'.
Usage
Usage on the same page
On the same page you can resolve page text variables through the {$:Var} format (shown above).
Usage in headers and footers: special references
If you want a GroupHeader, GroupFooter, SideBar, etc to call on page text variable in the main page, you need to include special reference information.
To explicitly reference the page text variable from the page being displayed add an asterisk to the page text variable's markup: {*$:Address} on the GroupFooter or GroupHeader page.
Example
{*$:Mountain} \\
{*$Namespaced}
Mt Ruapehu Page Text Variables
To include a page text variable from a header or footer see usage from other pages below.
When using page text variables for selection or ordering, don't put the curly braces around the variable name. The curly forms do a replacement before the pagelist command is evaluated.
Link markup within the contents of a hidden page text variable directive (as opposed to other ways of specifying PTVs) will not be cached as a link on the page and thus won't be seen by pagelist's link= option. If you want the link to be found by link=, you need to specify the PTV using non-directive markup, or else put the link on the page even if it's hidden within a false conditional: (:Linkme: [[PageToLink]]:) (:if false:){$:Linkme}(:ifend:)
The page text variable value is always the text that is written in the page.
It is only evaluated when the variable is printed/output to HTML.
To sort by a page text variable variable, all values in all pages are the not-yet-evaluated text strings, and the pagelist order function does what it can with them. It does not process/evaluate the text at this point.
E.g. With a page name in to format "yyyyMonth" it is simpler to use a PageVariable calculated in config.php, not a PageTextVariable:
$FmtPV['$NameToYearMonth'] = 'PSFT("%Y%m", strtotime($name))'; # see $FmtPV and PSFT
Page text variables will be assigned/evaluated before any conditional markup is evaluated. This effectively means that you cannot declare a PTV within an if...else condition; and also that a PTV will have a value even if it is set within a (:if false:)....(:ifend:) condition.
Usage - from within code (developers only)
The standard PageVar($pagename,$varname) function can return page text variables, but remember to include the dollar and colon like this:
$var=PageVar($pagename,'$:City')
It works by caching all page (text) variables it finds in a page (in $PCache) and returns the one requested.