00880: [[PmWiki/Page text variables]] change request
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.
- 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 :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
- 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.
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.
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?
>>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. ✓- You don't need
fmt={$FullName}#bycountry
whenfmt=#bycountry
will work just as well. ✓ - 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:) >>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
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}" "{$: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