[pmwiki-users] How do I check PTVs on other pages using conditional markup?

Martin Kerz mkerz at me.com
Mon May 14 07:14:53 CDT 2012

First of all, thanks for your help. I figured that the "=" was the problem. I wanted to access the PTV in the conditional and thought that I would need the "=" without it, everything works fine.


>> Am 11.05.2012 um 23:58 schrieb Peter Bowers:
>>> On Fri, May 11, 2012 at 10:44 AM, Martin Kerz <mkerz at me.com> wrote:
>>> (:if ( ! equal {={$?originpg}$:Prio} 0 ) :)
>>> :Priority:{{$?originpg}$:Prio}
>>> (:ifend:)
> So after your httpvariable is interpolated with a value of
> "Mygroup.Mypage" you would end up with a conditional that looks like
> this:
>>> (:if ( ! equal {=Mygroup.Mypage$:Prio} 0 ) :)
>>> :Priority:{Mygroup.Mypage$:Prio}
>>> (:ifend:)
> The use of the = in the first line indicates that you want it to get
> the value from the current page in the pagelist.  But then you specify
> the name of the page explicitly.  Perhaps you were looking for this:
>>> (:if ( ! equal {=$:Prio} 0 ) :)
>>> :Priority:{{$?originpg}$:Prio}
>>> (:ifend:)
> which says if the value of {$:Prio} on the current pagelist page is 0
> then provide a default value from {Mygroup.Mypage$:Prio}
> Do note that if this is an attempt to set a default value in a PTV
> this does not work.  As recently discussed
> (http://pmichaud.com/pipermail/pmwiki-users/2012-May/060230.html) you
> cannot dynamically set PTVs via markup.  PTVs are read from the "raw"
> text of your page, not from any marked-up version of the text.  Thus
> any PTV definition you create by markup will *not* be read when you
> try to read the PTV.
> Capabilities such as this (dynamically setting PTVs) could
> theoretically be requested via PITS, but the performance cost could be
> astronomical.  Imagine doing a pagelist where you were listing a PTV
> from each of a few hundred pages -- each page would have to be fully
> rendered (i.e., all markup rules run) in the process of obtaining the
> value of the PTV.  From a performance standpoint it would be
> unthinkable unless you were going to try to cache PTV values or
> something like that...
> However, an alternate PTV markup which accepted a default value would
> be quite do-able.  Basically you would choose your markup (stealing
> from wikish [which of course in turn steals from bash] I would use
> something like {$:varname:-DEFAULT VAL} ) and then you would create a
> markup which would parse that markup, pass the $:varname to PageVar(),
> check the return variable value and return either the variable value
> or the default value depending on whether it was set/unset.
> Here's the markup from stdmarkup.php
> ===(snip)===
> # {$var} substitutions
> Markup('{$var}', '>$[phrase]',
>  '/\\{(\\*|!?[-\\w.\\/\\x80-\\xff]*)(\\$:?\\w+)\\}/e',
>  "PRR(PVSE(PageVar(\$pagename, '$2', '$1')))");
> ===(snip)===
> Although completely untested I think that something based off of this
> might work:
> ===(snip)===
> # {$var:-dflt} substitutions
> Markup('{$var:-default}', '<{$var}',
>  '/\\{(\\*|!?[-\\w.\\/\\x80-\\xff]*)(\\$:?\\w+):-(.*?)\\}/e',
>  "PRR(PVSE(PageVar(\$pagename, '$2', '$1') : ? '$3'))");
> ===(snip)===
> Do note that this will only work with the "val ?: alt" syntax from PHP
> 5.3 or beyond -- nothing prior to that
> (http://www.php.net/manual/en/language.operators.comparison.php).  If
> you're still on an earlier version then you'll need to assign a
> variable or put it into a function or something...  If you want to put
> a variable in as the default then you will want to change the order of
> the rule to '>{$var}' or something...
> Again, that's untested -- it probably won't work out of the box but
> hopefully it points you in the right direction...
> If you weren't trying to set a default value of a PTV then ignore all
> my drivel above... :-)
> -Peter

More information about the pmwiki-users mailing list