(:groupheader:)(:Summary:Page variables automatically made available through natural or explicit page markup:) >>comment<< [[#singleline]] [-[[{=$FullName}|+]],-] \ [[#singlelineend]] >><< <:vspace> >>rframe font-size:smaller noprint clear=right<< !!!! Table of contents * [[#defining | Defining page text variables]] * [[#usage | Usage]] ** [[#usagesamepage | On the same page]] ** [[#usageotherpage | From other pages]] ** [[#usageincludedpage | On included pages]] ** [[#pagelists | With pagelists]] ** [[#templates | In templates]] ** [[#conditionals| With conditionals]] ** [[#withincode | Within code]] >><< <:vspace> 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. <:vspace> [[#defining]] !! Defining Page Text Variables <:vspace> There are three ways to define automated Page Text Variables: <:vspace> * use a [[TextFormattingRules#DefinitionLists | definition list]] - the normal pmwiki markup for a definition list will create a page text variable (:markup caption='Example definition list:' class="horiz":) :Name: Crisses "{$:Name}" (:markupend:) ->This creates a new variable that can be accessed by [@{$:Name}@] (becomes: "{$:Name}") in the page. <:vspace> * use a simple colon delimiter in normal text (:markup caption='Example colon delimited:' class="horiz":) Address: 1313 Mockingbird Lane <:vspace> "{$:Address}" (:markupend:) ->This creates the [@{$:Address}@] variable (variable markup becomes: "{$:Address}") in the page. <:vspace> * hidden [[PmWiki/PageDirectives | directive]] form - PmWiki markup that doesn't render on the page, but defines the variable (:markup caption='Example directive:' class="horiz":) (:Country: Transylvania :) "{$:Country}" (:markupend:) ->This creates the [@{$:Country}@] variable (variable markup becomes: "{$:Country}") in the page. <:vspace> [[#usage]] !! Usage [[#usagesamepage]] !!! Usage on the same page <:vspace> On the same page you can resolve page text variables through the [@{$:Var}@] format (shown above). <:vspace> [[#specialreferences]] !!! Usage in headers and footers: special references <:vspace> 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. (:markup caption='Example' class=horiz:) {*$:City} {{*$Group}/HomePage$:Summary} (:markupend:) To include a page text variable ''from'' a header or footer see [[#usageotherpage |usage from other pages]] below. -< Special references also apply to [[page variables(#specialreferences)]] and [[page list templates(#specialreferences)]]. <:vspace> <:vspace> [[#usageotherpage]] !!! Usage from other pages <:vspace> If you want to pull the data from another page, use the [@{Group/PageName$:Var}@] format. (:markup caption='Example:' class="horiz":) Suburb: Khandallah (:Lake:Taupo:) :Mountain:Mt Ruapehu <:vspace> ->"{PmWiki/PageTextVariables$:Suburb}" ->"{{$FullName}$:Lake}" ->"{PmWiki/PageTextVariables$:Mountain}" (:markupend:) <:vspace> [[#usageincludedpage]] !!! Usage from included pages <:vspace> Page text variables are never [[IncludeOtherPages|included]] from their source page. See [[#usageotherpage|Usage from other pages]] above to refer to a page text variable on another page. <:vspace> [[#pagelists]] !!! Usage with pagelists <:vspace> [[Page lists]] can also access the page text variables: (:markup caption='Example:' class="horiz":) (:pagelist group=PmWiki order=$:Summary count=6 fmt=#singleline:) (:markupend:) <:vspace> And to create pagelist formats (such as those documented at [[Site.Page List Templates]], [[PmWiki/Page Lists]], [[PmWiki/Page List Templates]], [[PmWiki/Page Variables]]. Store custom pagelists at [[Site.Local Templates]]). <:vspace> [[Page lists]] can also use page text variables to select pages : (:markup caption='Example:' class="horiz":) (:pagelist group=PmWiki $:City=Paris count=8 fmt=#singleline order=-name:) (:markupend:) ->lists pages having '$:City' set to 'Paris'. <:vspace> (:markup caption='Example: multiple selections with spaces' class="horiz":) (:pagelist group=PmWiki $:City="Addis Ababa,Paris" order=-$:Version count=8 fmt=#singleline:) (:markupend:) ->'quotes' must surround ''all'' the selections. <:vspace> * 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. <:vspace> [[#set]] !!! Testing if set or not set || border=0 cellpadding=4 rules=all || '''=-''' ||PTV is set (is not empty), eg [@(:pagelist $:Var=- :)@] || || '''=-?*''' ||PTV is not set (is empty), ie not one character followed by 0 or more characters, eg. [@(:pagelist $:Var=-?* :) @] || || '''=*''' ||display ''all'' pages, regardless of the page text variable (slow) || || '''=-*''' ||display ''no'' pages, regardless of the page text variable (slow) || <:vspace> <:vspace> [-Tip : [@(:if ! equal "{$:PTV}" "":)@] will test if PTV is empty/unset or not.-] <:vspace> <:vspace> (:markup caption='Example: Pages without a summary' class="horiz":) (:pagelist group=PmWiki $:Summary=-?* count=6 fmt=#singleline:) (:markupend:) <:vspace> [[#templates]] !!! Use page text variable in a template Display pages by Audience page text variable. (:markup caption='Example:' class="horiz":) >>comment<< [[#byaudience]] (:if ! equal '{=$:Audience}' '{<$:Audience}':) -<'''{=$:Audience}''': (:ifend:) [[{=$Name}]] [[#byaudienceend]] >><< (:pagelist group=PmWiki count=10 fmt=#byaudience order=-$:Audience:) (:markupend:) <:vspace> [[#conditionals]] !!! Use page text variables in [[PmWiki/conditional markup]] 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:)....(:if:)@] condition. <:vspace> [[#withincode]] !!! Usage - from within code (developers only) <:vspace> The standard @@PageVar($pagename,$varname)@@ function can return page text variables, but remember to include the dollar and colon like this: <:vspace> ->@@$var=PageVar($pagename,'$:City')@@ <:vspace> It works by caching all page (text) variables it finds in a page (in @@$PCache@@) and returns the one requested.(:groupfooter:) <:block>