Page text variables are string variables automatically made available through natural page markup or explicitly with page directive markup within the wiki text of the page.
There are three ways to define automated Page Text Variables:
:Name: Crisses "{$:Name}" |
"Crisses" |
{$:Name}
(becomes: "Crisses") in the page.
Address: 1313 Mockingbird Lane "{$:Address}" | Address: 1313 Mockingbird Lane "1313 Mockingbird Lane" |
{$:Address}
variable (variable markup becomes: "1313 Mockingbird Lane") in the page.
(:Country: Transylvania :) "{$:Country}" | "Transylvania " |
{$:Country}
variable (variable markup becomes: "Transylvania ") in the page.
On the same page you can resolve page text variables through the {$:Var}
format (shown above).
If you want a GroupHeader, GroupFooter, SideBar, etc to call on page text variable in the main page, you need to include 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.
{*$:City} | Addis Ababa |
To include a page text variable from a header or footer see usage from other pages below.
If you want to pull the data from another page, use the {Group/PageName$:Var}
format.
Suburb: Khandallah (:Lake:Taupo:) :Mountain:Mt Ruapehu ->"{PmWiki/PageTextVariables$:Suburb}" ->"{{$FullName}$:Lake}" ->"{PmWiki/PageTextVariables$:Mountain}" | Suburb: Khandallah
"Khandallah"
"Taupo"
"Mt Ruapehu"
|
Page text variables are never included from their source page. See Usage from other pages above to refer to a page text variable on another page.
Page text variables can be nested
: MailingAddress : {$:Address}, {$:City}, {$:Country} "{$:MailingAddress}" |
"1313 Mockingbird Lane, Addis Ababa, Transylvania " |
Another way you may nest PTVs is to make (part of) the variable name a variable in itself:
x:Test/Ptvb Contents of y on page {$:x}: {{$:x}$:y} | x:Test/Ptvb Contents of y on page Test/Ptvb: |
Page lists can also access the page text variables:
(:pagelist group=PmWiki order=$:Summary count=6 fmt=#singleline:) |
And to create pagelist formats (such as those documented at Site.Page List Templates, Page Lists, Page List Templates, Page Variables. Store custom pagelists at Site.Local Templates?).
Page lists can also use page text variables to select pages :
(:pagelist group=PmWiki $:City=Paris count=8 fmt=#singleline order=-name:) |
(:pagelist group=PmWiki $:Audience="*authors (intermediate)*,*administrators (intermediate)*" order=-$:Audience,name count=10 fmt=#singleline:) |
(:pagelist group=PmWiki $:City="Addis Ababa,Paris" order=-$:Version count=8 fmt=#singleline:) |
City: Addis Ababa (:pagelist group=PmWiki $:City=- count=10 fmt=#singleline:) | City: Addis Ababa |
=- | PTV is set (is not empty), eg (:pagelist $:MyPageTextVariable=- :)
|
=-?* | PTV is not set (is empty), ie is not set to one char followed by 0 or more chars, eg
(:pagelist $:MyPageTextVariable=-?* :)
|
=* | display all pages, the page text variable is irrelevant |
=-* | display no pages, the page text variable is irrelevant |
(:pagelist group=PmWiki $:Summary=-?* count=6 fmt=#singleline:) |
Display pages by Audience page text variable.
>>comment<< [[#byaudience]] (:if ! equal '{=$:Audience}' '{<$:Audience}':) -<'''{=$:Audience}''': (:ifend:) [[{=$Name}]] [[#byaudienceend]] >><< (:pagelist group=PmWiki count=10 fmt=#byaudience order=-$:Audience:) |
Page text variables will be assigned/evaluated before any conditional markup is evaluated. That means you can use page text variables with conditional markup, but not conditional markup within page text variables. For instance a PTV will have a value even if it is set within a (:if false:)....(:if:)
condition.
Data relevant to a page (the "Base" page) may now also be found in other groups. If the Base page is Main/HomePage, the data page could be Data-Main/HomePage. A new variable called $BaseName
, which automatically calculates the Base page name from the Data page name, and can be defined by including the following in config.php:
// The pattern for figuring out the basename of a page $BaseNamePatterns['/^Data-/'] = '';
Your pattern may vary.
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')
Actually, for text variables, PageVar
just calls PageTextVar($pagename,$varname)
, so your code can be sped up slightly by calling it directly, but it takes just the raw variable name without any leading characters, like this:
$var=PageTextVar($pagename,'City')
It works by caching all page text-variables it finds in a page (in $PCache
) and returns the one requested.
Page text variables were introduced in 2.2.0 beta 2.
This page may have a more recent version on pmwiki.org: PmWiki:PageTextVariables, and a talk page: PmWiki:PageTextVariables-Talk.