PageTextVariables from included pages

PageTextVariables used to work from included pages. I had them all over several websites. Now hyperlinks are busted everywhere, most have disappeared completely because their values are empty, and its hard to find a bad link when you cannot see it. Is there a way to restore using them from included pages like before? Maybe set an option like $UsePageTexVariablesFromIncludedPages = 1 ; I have hundreds of things get busted when this changed. --gnuzoo

If something recently broke, it was not intentional, and I'll try to fix it ASAP. Can you demo this creating pages in the Test/ group? Also, bug reports may be best added to PITS. --Petko

This is from wiki sites I made several years ago. Upgrading busted it. --gnuzoo

What markup used to work before and doesn't now? --Petko

I would set some PageTextVariables in an included page. In the page doing the including, sometimes I would set a PageTextVariable or two which would override the included page value, but use the same value for others that were set in the included page. In other words, the page doing the including has precedence. I could change all or some of the values in the local page. I liked it when the include directive was exactly like including another page was like the included page is part if the page being included. But now there is some crazy stuff going on with PageTextVariables. Using Baseline does not work I am trying to reference the same name on the included page and the including page on the including page. --gnuzoo

I don't think what you describe ever worked (without maybe some recipe): a PTV is read from either the included page, or from the including page, there is no way to have a default in one page but override it. If you upgraded from a version before 2.2.10 (14+ years and 167 releases ago), there was a change in $EnableRelativePageVars that changes how {$:Var} previously meant a variable in the including page (which is now {*$:Var}) while now it means a variable in the same page where {$:Var} is written, i.e. the included page (or header, footer, sidebar). This didn't have anything to do with having a default variable in one page, but override it in another page. In 2.2.122 (4.3 years ago) were added $DefaultUnsetPageTextVars and $DefaultEmptyPageTextVars but these are set in config.php not pulled from a page, see PageTextVariables#default. --Petko

I found a better way - CookBook Recipe HttpVariables - using session variables in included pages do not have crazy issues like PageTextVariables do such as Usage in headers and footers: special references, and Usage from other pages, and Usage from included pages.

> 14+ years
Omigosh! I am starting to feel old. I have been using pmwiki for 18+ years! Actually 19+ years! Searched old emails and found it all started November 11, 2004! Now I really feel old!
My recollection is it did work the way I described. The "code" from included page(s) was combined into the current page "code" and then processed as one big giant chunk of "code" for the page. There were no such issues as "Usage in headers and footers: special references", and "Usage from other pages", and "Usage from included pages".

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

Oops! I hope it doesn't change too much. I make extensive use of the 2nd type of PTV nesting... —Peter Bowers February 23, 2011, at 01:39 AM

Page text variables can be nested

: MailingAddress : {$:Address}, {$:City}, {$:Country}
, ,

", , "

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

Contents of y on page {$:x}:

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.

Use page text variables in 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.

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

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}


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

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.

 Sea: Tasman
  Ocean:  Southern

-> @@"{$:Sea}"@@
-> @@"{$:Ocean}"@@

(:Continent: Antartica:)
-> @@"{$:Continent}"@@
 Sea: Tasman
  Ocean:  Southern
" Southern"

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

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


Insect : Weta


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

What you can't do

Mismatch case in the page variable name

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

:Big bird:Moa

"@@{$:Big bird}@@" "@@{$:Bigbird}@@" 
Big bird

"{$:Big bird}" ""

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

:Island:       Rakiura
:Volcano:               Ngauruhoe                                   


" Rakiura" " Ngauruhoe " "Rotorua "

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

-<[[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"

To use with conditional markup put the conditional markup in the variable

LinkUrl: (:if TRUE:)[[Cookbook:Quotes]](:ifend:)

Wrong answer because [={$:LinkUrl}=] gets redefined in another example below.

This works:

AnotherLinkUrl: (:if TRUE:)[[Cookbook:Quotes]](:ifend:)


-> [-[[~ChuckG]] February 24, 2017, at 03:47 AM-]



Wrong answer because {$:LinkUrl} gets redefined in another example below.

This works:



ChuckG February 24, 2017, at 03:47 AM

This won't work as page text variables are calculated prior to expressions.

(:if TRUE:)
  LinkUrl: [[Cookbook:Quotes]]



See more examples at Test.Ptv

Usage in code

Defining new patterns for PTV (examples : bulleted lists, anchors, triple angle brackets)

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

Bulleted lists. For enabling PTV definition in bulleted lists, use this line in config.php (EemeliAro in Mailing list)

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

Anchors. For enabling multiline PTV definition delimited with anchors, use these lines in config.php (HansB in Mailing list). « The advantage of using anchors as PTVs is that you could reference those sections as PTVs and also as anchor sections, use them in urls for instance. The markers are also invisible. »

# make it possible to treat [[#section]] .... [[#sectionend]] as a PTV of name 'section'
$PageTextVarPatterns['[[#anchor]]'] =   "/(\\[\\[#(\\w[-\\w]*)\\]\\](?: *\n)?)(.*?)(\\[\\[#\\2end\\]\\])/s";

<<< (myvar) angle brackets >>>. For enabling multiline PTV definition delimited with triple angle brackets, use these lines in config.php (HansB in Mailing list).

Markup('<<<var', '<split', '/<<<\\s*?\\((\\w[-\\w]*) *\\)(.*?)>>>/s', '$2' );
$PageTextVarPatterns['<<<var...>>>'] = '/(<<<\\s*?\\(*(\\w[-\\w]*) *\\)(?!\\))\\s?)(.*?)(>>>)/s';

Page Text Variable calls & Markup Expressions

You can use a PTV call in a markup expression, but due to order of processing, you cannot use a markup expression inside of a PTV variable name. The following will fail:

(:if exists Profile-Data.{Members/Hosts$:{(ftime "%Y%m")}} :)

Instead create a Page Variable in config.php, and use it in the PTV:

$FmtPV['$YYYYMM'] = 'PSFT("%Y%m")';

Then this will work:

(:if exists Profile-Data.{Members/Hosts$:{$YYYYMM}} :)


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

(:include {$:Abstract} lines=4:)
->[[{$:Abstract} | more ...]]

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

(:include TemplateThatUsesParameter:)
(:include TemplateThatUsesParameter:)

See Include with PTV, IncludeWithPTV2

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
(:div id='{$:project}_small':)


Can someone give me an example of using page text variables in a skin template? I read it can be done - but how?


Where to find markup fmt=#singleline used in [PmWiki/PageTextVariables]?

Here it is (it is near the top of the source text):
[-[[{=$FullName}|+]],-] \

How to make multiline PTV's not break conditional markup?

(:PtvOne: some
(:if ! equal "{$:PtvOne}" "":)something(:else:)nothing(:ifend:)\\
but markup works: {$:PtvOne}

(:if ! equal "some thing" "":)something(:else:)nothing
but markup works: some thing

This is currently unsupported, may be possible to write an addon. The thing to remember is that when you type {$:PtvOne} in the page, the value of that variable is placed very early in the page, and then the conditional syntax is no longer correct. Same if you have a quote in the value. --Petko June 07, 2018, at 04:46 PM

If you just want to test for empty PTVs, you can put this in a config file:

# {(ptvlen "{$FullName}" "MyPTV")} # not $:MyPTV
# useful to test for a ptv that contains multiple lines or quotes that might break the markup
# E.G. (:if !equal {(ptvlen "{$FullName}" "MyPTV")} 0:) tests whether a non-empty MyPTV exists
# This is similar to strlen in PmWiki:MarkupExpressions, 
# but avoids breaking conditionals if PTV is multiline
  $MarkupExpr['ptvlen'] = 'PTVlen($args[0],$args[1])';
  function PTVlen ($page, $ptv) {
    $var=PageTextVar($page,$ptv); # no $: or quotes
    return strlen($var);   

RandyB June 08, 2018, at 02:00 PM

This is a talk page for improving PmWiki.PageTextVariables.