Hi all,
I got a bit perplexed about the order in which templates are expanded. I tested a template - inside a ParserFunction - inside a parameter (representing the |default}} value ), but, to my big surprise, the template obviously expanded inside the parameter! That is, :
1. before ParserFunction (#if: evaluated "yes, a valid string") 2. which was returned as the default value for the parameter.
Simplified: In the simple parameter "{{{param|default}}}" I replaced "default" by the slightly more complex expression :
{{{param|{{#if:{{GetSomeTitle}}|{{GetSomeTitle}}}}}}} which returned = SomeTitle
or, more readable:
{{{param| {{ #if: {{GetSomeTitle}} | {{GetSomeTitle}} }} }}} = SomeTitle
(the template GetSomeTitle returns the string "SomeTitle").
What surprised me was that the template (seemingly) were expanded BEFORE the parameter, which I expected to be resolved before calling any subsequent templates. Thus it seemd like a hen-or-egg-first phenomenon... :)
Obviously I must have missed something.
Is there any documentation page which correctly describes the order in which evaluation is performed of the following (on expand / parse) :
a. Strip for "no parse". b. Magicwords c. Parameters d. Templates e. Variables (StringFunctions) f. ParserFunctions (#if:, #ifeq: etc.) g. Unstrip
And also whether any of the above (forgot some?) are repeated before and/or after any of the other in the list.
All shared insights on this topic would be much appreciated, TIA.
Regards,
// Rolf Lampa
I'm fairly sure that all curly-brace constructs are simply expanded from the inside out, from left to right. Your construct would be evaluated like:
{{{param|{{#if:{{GetSomeTitle}}|{{GetSomeTitle}}}}}}} {{{param|{{#if:SomeTitle|{{GetSomeTitle}}}}}}} {{{param|{{#if:SomeTitle|SomeTitle}}}}} {{{param|SomeTitle}}}
You might observe that if {{{param}}} is defined, it's a waste of time to calculate the default, but currently the curly-brace expander isn't that clever. As for the rest of your questions, you have to look in Parser.php for the whole sordid multipass story of the exact parsing order, really.
Simetrical skrev:
I'm fairly sure that all curly-brace constructs are simply expanded from the inside out, <snip>
OK, inside out makes sense, but the order of things is still... obscure.
I mean, if I don't first evaluate the parameters, before sesding them to a template... but here a template is expanded before the parameter...
...look in Parser.php for the whole sordid
=)
I will.
Regards, // Rolf Lampa
wikitech-l@lists.wikimedia.org