Aktuelle Änderungen - Suchen:

PmWiki (deutsch)

Bearbeiten


Englisch:

PmWiki

pmwiki.org

Seiten Text Variablen

Autoren (Fortgeschrittene) (deutsche Übersetzung der Seite PmWiki.PageTextVariables, Stand englisch)

Page Text Variables were introduced in 2.2.0 beta 2. These are page variables automatically made available through natural page markup or explicit page markup within the wiki text of the page.

Notes
ConditionalMarkup works fine with page text variables. Page text variables don't recognize ConditionalMarkup. This is also true for include other pages.
Page text variables don't honor (:if:). This is the same way that doing (:include OtherPage#section:) doesn't look to see if [[#section]] is inside of an (:if:)...(:ifend:) construct of some sort.

Defining Page Text Variables

There are three ways to define automated Page Text Variables:

  • use a definition list - the normal pmwiki markup for a definition list will create a page text variable
Example:
:Name: Crisses
"{PmWiki.PageTextVariables$: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:
Address: 1313 Mockingbird Lane

"{PmWiki.PageTextVariables$: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:
(:Country: Transylvania :)
"{PmWiki.PageTextVariables$:Country}"

"Transylvania "

This creates the {$:Country} variable (variable markup becomes: "Transylvania ") in the page.

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

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.

Example
{*$:City}

To include a page text variable from a header or footer see usage from other pages below.

Usage from other pages

If you want to pull the data from another page, use the {Group/PageName$:Var} format.

Example:
Suburb: Khandallah
(:Lake:Taupo:)
:Mountain:Mt Ruapehu

->"{PmWiki/PageTextVariables$:Suburb}"
->"{{PmWiki.PageTextVariables$FullName}$:Lake}"
->"{PmWiki/PageTextVariables$:Mountain}"

Suburb: Khandallah

Mountain
Mt Ruapehu
"Khandallah"
"Taupo"
"Mt Ruapehu"

Usage from included pages

Page text variables are expanded relative to their source page, so they work as you would expect.

Nested page text variables

Page text variables can be nested

Example:
: MailingAddress :
{PmWiki.PageTextVariables$:Address},
{PmWiki.PageTextVariables$:City},
{PmWiki.PageTextVariables$:Country}
"{PmWiki.PageTextVariables$:MailingAddress}"
MailingAddress
1313 Mockingbird Lane, Addis Ababa, Transylvania

"1313 Mockingbird Lane, Addis Ababa, Transylvania "

Another way you may nest PTVs is to make (part of) the variable name a variable in itself: (check out Ptva)

Example:
x:Test/Ptvb
Contents of y on page
{PmWiki.PageTextVariables$:x}:
{{PmWiki.PageTextVariables$:x}$:y}

x:Test/Ptvb Contents of y on page Test/Ptvb: hello

Usage with pagelists

Page lists can also access the page text variables:

Example:
(:pagelist group=PmWiki order=$:Summary
count=8
fmt=Cookbook/PagelistTemplateSamples#oneline:)

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 :

Example:
(:pagelist group=PITS $:Category=Feature
count=8
fmt=Cookbook/PagelistTemplateSamples#oneline
order=-name:)
lists pages having '$:Category' set to 'Feature'.
Example: multiple selections
(:pagelist group=Cookbook $:Version=1,2
order=-$:Version count=8
fmt=Cookbook/PagelistTemplateSamples#oneline:)
lists pages having a '$:Version' of '1' or '2'.
Example: multiple selections with spaces
(:pagelist group=PmWiki $:City="Addis
Ababa,Paris" order=-$:Version count=8
fmt=Cookbook/PagelistTemplateSamples#oneline:)
'quotes' must surround all the selections.
Example: Pages with City variable set
City: Addis Ababa
(:pagelist group=PmWiki $:City=-
count=10
fmt=Cookbook/PagelistTemplateSamples#oneline:)

City: Addis Ababa

City variable is set.
  • 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.

Testing if set or not set

=- 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
Example: Pages without a summary
(:pagelist group=PmWiki $:Summary=-?*
count=10 
fmt=Cookbook/PagelistTemplateSamples#oneline:)

Use page text variable in a template

Display pages by Country page text variable.

Example:
[@
[[#bycountry]]
(:if ! equal {{=$FullName}$:Country}
{{<$FullName}$:Country} :)
-<'''[[{{=$FullName}$:Country}]]''':
 
(:ifend:)
[[{=$FullName}]]
[[#bycountryend]]
@]
(:pagelist group=PmWiki count=6
fmt={PmWiki.PageTextVariables$FullName}#bycountry:)
[[#bycountry]]
(:if ! equal {{=$FullName}$:Country} {{<$FullName}$:Country} :)
-<'''[[{{=$FullName}$:Country}]]''':  
(:ifend:)
[[{=$FullName}]]
[[#bycountryend]]
some parts of this example are not working correctly, should not display all pages

Usage - other

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.

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')

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.

PageTextVar relies on the $PageTextVarPatterns variable (which can be used to extend the recognized formats for page text variables in a page). In the older 2.2.0 Beta versions of PmWiki, this variable wasn't initialized until stdmarkup.php was run, after config.php was executed. Thus, if you needed to use page text variables inside config.php, you had to initialize it yourself. This is no longer necessary, but for those who are still running earlier versions of the beta series, here's the value to use:

 SDVA($PageTextVarPatterns, array(
    'var:' => '/^:*\\s*(\\w[-\\w]*)\\s*:[ \\t]?(.*)$/m',
    '(:var:...:)' => '/\\(: *(\\w[-\\w]*) *:(?!\\))\\s?(.*?):\\)/s'));

Other information:

  • Pm's post about line breaks documents use of the directive and mentions customization of the markup.
  • Pm's post responding to a request for a summary in response to a request for documentation.
  • Pm's post announcing the release of 2.2.0 beta 2 and providing examples.
  • Pm's post planning for 2.2.0
  • Lots of older posts with references to "PData" including an some extensive threads with lots of brainstorming about markup including, specifically, the WikiPaths thread started by Martin. (wikipath recipe finally released)

Usage notes

Lists can be separated with leading spaces (a la Site.Blocklist or Site.InterMap)

Example:
 Sea: Tasman
  Ocean:  Southern

->"{PmWiki.PageTextVariables$:Sea}"
->"{PmWiki.PageTextVariables$:Ocean}"
 Sea: Tasman
  Ocean:  Southern
"Tasman"
" Southern"

Lists can have leading or trailing spaces around the page variable name

Example:
Insect : Weta
:Bird  : Kiwi
: Tree: Kauri
:  Flower : Kowhai

"{PmWiki.PageTextVariables$:Insect}"
"{PmWiki.PageTextVariables$:Bird}"
"{PmWiki.PageTextVariables$:Tree}"
"{PmWiki.PageTextVariables$:Flower}"

Insect : Weta

Bird
Kiwi
Tree
Kauri
Flower
Kowhai

"Weta" "Kiwi" "Kauri" "Kowhai"

What you can't do

Mismatch case in the page variable name

Example:
river: Whanganui
Range: Southern Alps

->[-(lowercase)-]
"{PmWiki.PageTextVariables$:river}"
->[-(uppercase)-]
"{PmWiki.PageTextVariables$:River}"
->[-(lowercase)-]
"{PmWiki.PageTextVariables$:range}"
->[-(uppercase)-]
"{PmWiki.PageTextVariables$:Range}"

river: Whanganui Range: Southern Alps

(lowercase) "Whanganui"
(uppercase) ""
(lowercase) ""
(uppercase) "Southern Alps"

Have embedded (you really didn't expect that did you) spaces in the page variable name

Example:
:Big bird:Moa

"{$:Big bird}"
"{PmWiki.PageTextVariables$:Bigbird}" 
Big bird
Moa

"{$:Big bird}" ""

Note that leading and trailing spaces in the page variable text are retained

Example:
:Island:       Rakiura
:Volcano:               Ngauruhoe      
                            
:Caldera:Rotorua                       
                 

"{PmWiki.PageTextVariables$:Island}"
"{PmWiki.PageTextVariables$:Volcano}"
"{PmWiki.PageTextVariables$:Caldera}"
Island
Rakiura
Volcano
Ngauruhoe
Caldera
Rotorua

" Rakiura" " Ngauruhoe " "Rotorua "

Use natural page names, ie normal page name preprocessing does not occur

Example:
-<[[PmWiki.Page text variables]]
"{PmWiki.Page text variables$:Summary}"
-<[[PmWiki.PageTextVariables]]
"{PmWiki.PageTextVariables$:Summary}"
PmWiki.Page text variables "{PmWiki.Page text variables$:Summary}"
PmWiki.PageTextVariables "Page variables automatically made available through natural or explicit page markup"

Use with conditional markup

Example
(:if name
{PmWiki.PageTextVariables$FullName}:)
LinkUrl: http://dilbert.com
(:else:)
LinkUrl: [[Cookbook:Quotes]]
(:ifend:)

"{PmWiki.PageTextVariables$:LinkUrl}"
[-{PmWiki.PageTextVariables$FullName}-]

LinkUrl: Cookbook:Quotes

"Cookbook:Quotes" PmWiki.PageTextVariables

See more examples at Test.Ptv

Questions

How can I get the page text variable to be evaluated only when it is declared, rather than each time it is used. For example I want to do the following, where the link refers back to the page with the included text

(:Abstract:{Programme.Abstracts$RandomSection}:)
(:include {$:Abstract} lines=4:)
->[[{$:Abstract} | more ...]]
:Quote:{Cookbook.Quotes$RandomSection}
{PmWiki.PageTextVariables$:Quote}
{PmWiki.PageTextVariables$:Quote}
{PmWiki.PageTextVariables$:Quote}
Quote

Is there a way to overwrite Page text variables, for including the same Template twice? E.g.:

(:parameter:value1:)
(:include TemplateThatUsesParameter:)
(:parameter:value2:)
(:include TemplateThatUsesParameter:)

It is possible to enable PTV definition in bulleted lists by entering this line in config.php

  $PageTextVarPatterns['* var:'] = '/^(\\**\\s*(\\w[-\\w]*)\\s*:[ \\t]?)(.*)($)/m';

Thanks to EemeliAro (from the Mailing list).

Is it possible to use complex searches for PTV through pagelist? For example using regexp like this: (pagelist $MyVar="<regexp match pattern>")? Maybe a cookbook recipe can be provided for this? Also is there a possibility to achieve complex pagelist searches based on PTV-match conditions? For example to search for all pages where PTV1=<xxx> | PTV2!=<yyy>, or some other boolean expression... I wonder if this is something that can be cookbooked?

<< Seitenspezifische Variablen | Dokumentations-Index | Formatierungsanweisungen im Ausdruck >>

Bearbeiten - Versionen - Druckansicht - Aktuelle Änderungen - Suchen
Zuletzt geändert am 20.03.2008 04:14 Uhr