[pmwiki-users] RFC: hypothetical PageVariableExtensions recipe

Dominique Faure dominique.faure at gmail.com
Wed Apr 12 11:40:56 CDT 2006


On 4/12/06, Patrick R. Michaud <pmichaud at pobox.com> wrote:
> On Wed, Apr 12, 2006 at 05:28:49PM +0200, Dominique Faure wrote:
> >   (:initvars myvariable='my value' answer=42:)
> >
> > This markup defines two variables. Despite their values are provided
> > with the regular syntax: {$myvariable} or {$answer}, they couldn't be
> > reached directly from other pages as in {Group.Page$answer} (BTW, this
> > is the 1st and I fear unavoidable issue).
>
> It can be made to be reachable from other pages; the variables
> just have to be turned into page attributes.  This isn't that
> difficult -- PmWiki already does this for the (:title:), (:keywords:),
> and (:description:) pages, and in the Cookbook it does it for
> the "Summary:", "Version:", and "Votes:" properties.  (I.e., someone
> can write {Cookbook.RandomQuote$Summary} to get the summary of the
> Cookbook.RandomQuote page.)
>

I'll look on this!


> > The second issue is that I couldn't (for now) mix variables
> > and conditions:
> >   (:initvars var='something':)
> >   (:if false:)
> >   (:initvars var='nothing':)
> >   (:if:)
> >   var's value is {$var}
> > renders as:
> >   var's value is nothing
> > which is not what is expected.
>
> ...welcome to PmWiki's chicken-and-egg problem.  The question is
> one of ordering -- in this case, the ordering between the
> (:initvars:) markup and the (:if:) markup.
>
> If we say that (:initvars:) is to be processed before (:if:),
> then one cannot use conditional markups to control (:initvars:).
>
> If we say that (:initvars:) is to be processed after (:if:),
> then we cannot use page variables set by (:initvars:) as part
> of an (:if:) conditional -- i.e., we cannot do
>
>     (:initvars super=hello:)
>     (:if equal {$super} "hello":)
>     Alas, we'll never see this.
>     (:if:)
>
> As I've mentioned a couple of times before -- I don't yet have a
> good answer to these problems except by drastically re-working
> PmWiki's formatting engine (likely breaking a lot of recipes
> and sites in the process).
>
> However, I do have some mediocre answers to the problem, such as
> using different directives depending on when we want the variable
> to be initialized, but I fear that approach will simply end up
> being too confusing to be practical.
>
> Adding this sort of capability is something I definitely want to
> do for PmWiki, but I'm waiting for a good answer.
>
> What order are you planning to use for (:initvars:), {$...},
> and (:if:) markups?
>
> Pm
>

I'm already using a "cheat" to allow (:initvars var1={$var2}:), having
it defined before {$vars}:

  Markup('!{$var}', '<{$var}',
  "/\\(:(?i:initvars)(\\s+.*)?\\s*:\\)/e",
"PZZ(InitPageVars(\$pagename,PSS('$1')))");

and forcing variable evaluation when handling markup parameters with a
line of code like below:

  $v = preg_replace($MarkupTable['{$var}']['pat'],
$MarkupTable['{$var}']['rep'], $v);

and I was wondering if something equivalent couldn't be done with
(:if:) markup ?

Regards,
Dom

--
The difference between theory and practice in theory is much less
than the difference between theory and practice in practice.
 — Randal L. Schwartz




More information about the pmwiki-users mailing list