Forum:Expanding Arguments in Different Contexts

From Fallen London Wiki (Staging)
Forums: Index > Help Desk > Expanding Arguments in Different Contexts

Expanding Arguments in Different Contexts[edit]

While working with {{Action}}, I would like to expand the value passed to {{{Challenge information}}} twice, once with #var:embedcontext empty and once with content. Long story short, Mediawiki seems to be bending over backwards to stop me from doing this. I've found a variety of tricks (Templates, templates-of-templates, parser functions, Lua) that let me change which context the parameter is expanded into. But no matter what I do, the first time it's expanded it seems to get cached and that's how it shows up forever more.

Is there any way to trick Mediawiki into evaluating the same wikitext twice with different #var values?

Context for why I'm doing this: We want the Challenge info displayed on the page, obviously. I would also like to store that value into a SMW property, for displaying on other pages. E.g. on a quality page, the list of challenges against that quality could have challenge info as footnotes.

There are a number of potential issues with this. First and foremost is Categories and Properties set by {{Use}}. But also cases like e.g. Persuade Furnace where the Challenge info includes a table with dozens of rows. Both of these cases can be handled simply by #var:embedcontext. Other approaches would require an amount of regex pattern-wrangling that I would strive to avoid if there's another way.

- PSGarak (talk) 19:03, 16 February 2022 (UTC)

I only kinda understand the problem. Could you provide a minimal working (or, in this case, non-working) example which would illustrate the issue? -- RagCall (talk) 14:35, 17 February 2022 (UTC)
Ok, take a look at staging:User:PSGarak/Sandbox.

The test cases set a variable named "test" to one value, and then call a template, passing {{#var:test}} as the {{{1}}} parameter. The templates set "test" to various values, interleaved with expanding the argument {{{1}}}

In the first case, "test" is set to a second value, the arg value is printed, "test" is set to a third value, and the arg value is printed. Result: Both expansions are set to the second value. Meaning that setting the variable in the template does affect the value of the parameter! The arg expands to a value only set inside the template. But both expansions are set to the same value, regardless of re-setting the variable to different values.

In the second case, the arg value is printed first, and then more setting values and printing. In all cases the arg takes the value it had before any variables were set.

Let me know if you need me to explain this better, it made my head hurt a little bit. It's got to do how state and scope intermingle through multiple levels of template calls. PSGarak (talk) 15:31, 17 February 2022 (UTC)
I also don't completely understand the situation (so sorry if what I'm saying is obvious or in the wrong direction), but I love sleuthing for little problems like this and have some thoughts (and questions)!

Why do you even try to pass a variable to a template? Variables are global to a page and all its included templates (even if they were created in said templates), so where's the need? And needlessly passing it through parameters seems to produce weird results. Since the variable updates are made linearly, to change a variable's behavior inside a template the template itself must be suited to do so. CarrONoir (talk) 02:02, 18 February 2022 (UTC)
The thing with passing the variable to a template was the minimal test case. What I really want to have happen is something like this.

Passed as an argument to {{Action}}:
|Challenge information = Difficulty increased by {{Use|Wounds|Type=Math}}

For the purpose of display on the Action's own page, the {{Use}} should expand into [[File:...]] [[Wounds]] [[Category:Wounds Formula Use]]{{#set:Uses = Wounds;Math}}.

When the action is embedded via {{Options}}, the {{Use}} call expands into [[File:...]] [[Wounds]], with no Category link or #set call. If a {{Variant table}} were passed as part of the Challenge information, that is also suppressed. I would like to use this same version for storing in Property:Has challenge info, so we don't end up sticking categories on other pages by accident.

Right now, inside {{Action}}, I can get {{{Challenge information}}} to expand into the former just by calling it. And I can get it to expand into the latter by calling the following, which is also what {{Options}} does:
{{#vardefine:embedcontext|challenge}}
{{{Challenge information}}}
{{#vardefine:embedcontext|}}
But I can't get both expansions, which is what I want.

This happens because {{Use}} and {{Variant table}} use #var:embedcontext under the hood, by design. So a variable isn't being passed directly, it's included by another template. Still, that variable behavior is basically part of the template's contract.

- PSGarak (talk) 03:30, 18 February 2022 (UTC)