00880: [[PmWiki/Page text variables]] change request

Summary: Page text variables change request
Created: 2007-02-07 20:54
Status: Closed, issues resolved
Category: Feature
From: Simon
Priority: 4
Version: 2.0 beta
OS: n/a


Page text variables are a useful lightweight include mechanism.

I have been endeavouring to product some real working examples to reduce the learning curve for others.

I have the following suggestions (and questions)
  • question: are page text variable names deliberately case sensitive?
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"

Yes, just as page names are on most systems. If you want to change this you'll need to poke at the PageTextVar function in pmwiki.php. —Eemeli Aro July 28, 2009, at 06:07 AM

  • suggestion: remove leading and trailing spaces around the page text variable text
Fish:                        Inanga                                             
:Island:           Rakiura
:Volcano:       Ngauruhoe                
(:Hiker:    Simon   :)

"{$:Fish}" | "{$:Island}" | "{$:Volcano}" | "{$:Caldera}" | "{$:Hiker}"

Fish: Inanga


" Inanga " | " Rakiura" | " Ngauruhoe " | "Rotorua " | " Simon "

incorrect should remove leading and trailing spaces

If trimming spaces is required for a wiki, an admin could set the following in config.php. --Petko August 21, 2009, at 09:05 PM

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

Still like to see this as the default simon August 22, 2009, at 01:35 AM

Please don't make space-trimming the default. If I put a space there then I expect it to be there. If I don't want it then I don't put it. I don't want pmwiki making assumptions about whether I did or didn't want spaces... Peter Bowers September 01, 2009, at 09:31 PM

See also
Test.PageTextVariables, Test.PageListWithPgVar, Test.PageListOrderingWithPgVar, Test.Ptv
PITS.00855, PITS.00884

When using page text variables for selection or ordering, don't put the curly braces around the variable name.

In other words, it's $:City=Paris and not {$:City}=Paris.

City: Paris
(:pagelist group=PmWiki $:City=Paris count=8 fmt=Cookbook/PagelistTemplateSamples#oneline:)

City: Paris

Similarly, to order results by city, one uses order=$:City and not order={$:City}. The curly forms do a replacement before the pagelist command is evaluated.

Try reworking the examples with this in mind and see if it works as you expect.

Pm February 08, 2007, at 02:59 PM

Thanks Pm, fixed examples and this PITS entry.

Usage in pagelists doesn't seem quite right to me,
perhaps $:City=* should mean all pages with a page text variable named 'City' defined (rather than all pages) and $:City=-* should mean all pages with no page text variable named 'City' defined.
Fully agree with this suggestion. See 01136 for my proposed solution. Peter Bowers September 01, 2009, at 09:31 PM
Finally my usage of them in pagelist template formats doesn't seem to work

Added another problem with use in page lists

Examples explained or closed

Usage with pagelists

When using page text variables to select pages, the markup is counter-intuitive, syntax is $:ptv=- to show all pages, one might expect $:ptv=* (doctrine of least surprise)

With all other expressions, * means "zero or more characters", $:ptv=- means not empty, and it is the same as $:ptv=?* (one or more characters) which you may find more intuitive. --Petko August 21, 2009, at 09:09 PM

This is a wilecard character so I'm happy with the clarification, thanks. Curious where the "-" comes from though. simon August 22, 2009, at 01:35 AM

Usage in a list template

  • question: Are the =$ and <$ page text variables working as expected?
(:template default order=$:Country $:Country=-:)
(:if ! equal '{=$:Country}' '{<$:Country}' :)
(:pagelist group=PmWiki count=12 fmt=#bycountry:)

(:template default order=$:Country $:Country=-:)



Transylvania :



Three things:

  1. {{=$FullName}$:Country} is a bit verbose when {=$:Country} means the same thing. ✓
  2. You don't need fmt={$FullName}#bycountry when fmt=#bycountry will work just as well. ✓
  3. You're being tripped over by using the count=12 parameter that's making your list only contain pages that have no $:Country set; hence the conditional is always (also the first time) equivalent to (:if ! equal '' '' :) and hence false. ✓

Here's a fixed pagelist:

(:pagelist group=PmWiki count=12 fmt=#bycountry order=-$:Country:)
Transylvania :


Eemeli Aro July 28, 2009, at 06:07 AM

(:pagelist group=PITS $:From=Simon fmt=#pitsentry count=4:)
* [-[[{=$FullName}]] ''{=$:Status}'' {=$:Summary}-]

incorrect shows no pages

The reason there are no pages to show is because there are no PITS pages with $:From=Simon; you've always used [[~Simon]] instead. Hence:

(:pagelist group=PITS $:From=??~Simon]] fmt={$FullName}#pitsentry count=4:)
  • PITS.00162 Closed - fixed for 2.0.beta1 Move formatting of $PageLogoFmt into template
  • PITS.00250 Closed Provide a "wikiright" to match the existing wikileft
  • PITS.00269 Closed - not a bug %right% need blank line before and after
  • PITS.00396 Closed (added for 2.2.3) Creating uploads directory error message may require tidy

Eemeli Aro July 28, 2009, at 06:07 AM

Undeclared page variables

  • question: undeclared page variables are not shown, this is intended behaviour cf invalid page text variable names
:invalid name:with embedded space
"{$:invalid name}"
invalid name
with embedded space

"{$:invalid name}" ""

Two different things are happening here. With {$:invalid name} you've included a space in the page text variable name, which can't happen and hence isn't picked up by the '{$var}' markup rule. This is good and to be expected, since you'll see it eg. on page preview and can fix it. With {$:undeclared} the undeclared value has a string equivalent of '', which is as expected. —Eemeli Aro July 28, 2009, at 06:07 AM