Nested page text variables
Note: The following examples in this section describe a behavior, which was not defined as a feature by design, but which is more like a side effect. Be advised not to rely on nested PTVs, as their processing may change in the future. --Petko June 19, 2010, at 07:54 PM
Page text variables can be nested
Example:
: MailingAddress : {$:Address},
{$:City}, {$:Country}
"{$:MailingAddress}"
| - MailingAddress
- , ,
", , "
|
Another way you may nest PTVs is to make (part of) the variable name a variable in itself:
Example:
x:Test/Ptvb
Contents of y on page {$:x}:
{{$:x}$:y}
| x:Test/Ptvb
Contents of y on page Test/Ptvb:
hello
|
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.
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.
Note: The following examples in this section describe a behavior, which was not defined as a feature by design, but which is more like a side effect. Be advised not to rely on conditionals when you set a PTV, as their processing may change in the future. --Petko June 19, 2010, at 07:54 PM
In the example below, the condition will output the text '1 is equal to 1'; however, the value of 'cond1' will be 23, since both PTV assignments are evaluated (before the conditional), but the cond1:23 is evaluated last, and overrides the initial cond1:19.
(:if equal 1 1:)1 is equal to 1
(:cond1:19:)
(:else:)1 is NOT equal to 1?!
(:cond1:23:)
(:if:)
The value of 'cond1' is {$:cond1}
| 1 is equal to 1
The value of 'cond1' is 23
|
You can however embed a conditional in a PTV assignment. Notice the format of the declaration below uses the non-hidden assignment form.
cond2:(:if equal 1 1:)19(:else:)23(:if:)
The value of 'cond2' is {$:cond2}
| cond2:19
The value of 'cond2' is 19
|
You cannot use the hidden form of PTV assignments, with an embedded condition. You basically get garbage output:
(:cond3:(:if equal 1
1:)19(:else:)23(:if:):)
The value of 'cond3' is {$:cond3}
| The value of 'cond3' is (:if equal 1 1
|
But, you can take advantage of the fact that PTV assignments are made before conditions are evaluated, and hide the PTV assignment within a condition which evaluates to false, and thus is not displayed. In the example below we're using embedded conditions, and so we number the if statements:
(:if1 false:)
cond4:(:if2 equal 1
1:)19(:else2:)23(:if2:)
(:if1:)
The value of 'cond4' is {$:cond4}
| The value of 'cond4' is 19
|
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
List names can be separated with leading spaces (a la Site.Blocklist or Site.InterMap),
but list values may only have one leading space.
Example:
Sea: Tasman
Ocean: Southern
-> @@"{$:Sea}"@@
-> @@"{$:Ocean}"@@
(:Continent: Antartica:)
-> @@"{$:Continent}"@@
| Sea: Tasman
Ocean: Southern
"Tasman"
"Antartica"
|
Lists can have leading or trailing spaces around the page variable name
Example:
Insect : Weta
:Bird : Kiwi
: Tree: Kauri
: Flower : Kowhai
"@@{$:Insect}@@"
"@@{$:Bird}@@"
"@@{$:Tree}@@"
"@@{$: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)-] "{$:river}"
->[-(uppercase)-] "{$:River}"
->[-(lowercase)-] "{$:range}"
->[-(uppercase)-] "{$: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}@@" "@@{$: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
"@@{$:Island}@@"
"@@{$:Volcano}@@"
"@@{$: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}"
|
|
To use with conditional markup put the conditional markup in the variable
this won't work as page text variables are calculated prior to expressions.
See more examples at Test.Ptv
Usage in code
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'));
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}
{$:Quote}
{$:Quote}
{$: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:)
See Include with PTV, IncludeWithPTV2
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?
Is there any possibillity to include PageTextVariables in some other MarkUp? Something like that:
(:div id={{=$Name}$:project}}_small :)
Yes. Inspect the source to see that the following works. —
Eemeli Aro July 28, 2009, at 06:29 AM
(:project:bob:)
(:div id='{$:project}_small':)
blah
(:divend:)
|
|