Description:
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.
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
Fish: Inanga :Island: Rakiura :Volcano: Ngauruhoe :Caldera:Rotorua (:Hiker: Simon :) "{$:Fish}" | "{$:Island}" | "{$:Volcano}" | "{$:Caldera}" | "{$:Hiker}" | Fish: Inanga
" Inanga " | " Rakiura" | " Ngauruhoe " | "Rotorua " | " Simon " |
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
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.
Added another problem with use in page lists
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
>>comment<< [[#bycountry]] (:template default order=$:Country $:Country=-:) (:if ! equal '{=$:Country}' '{<$:Country}' :) -<'''{=$:Country}''': (:ifend:) [-[[{=$FullName}]]-] [[#bycountryend]] >><< (:pagelist group=PmWiki count=12 fmt=#bycountry:) | Transylvania :
|
Three things:
{{=$FullName}$:Country}
is a bit verbose when {=$:Country}
means the same thing. ✓
fmt={$FullName}#bycountry
when fmt=#bycountry
will work just as well. ✓
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:) >>comment<< [[#pitsentry]] * [-[[{=$FullName}]] ''{=$:Status}'' {=$:Summary}-] [[#pitsentryend]] >><< |
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:) |
|
—Eemeli Aro July 28, 2009, at 06:07 AM
:invalid name:with embedded space "{$:invalid name}" "{$:undeclared}" |
"{$: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