Is there a way to set a "new" parameter, internally to a template or other page?

Viewed 28

Let's say I have some page which can take two parameters, x and y. I often find myself doing things in that page like in this silly little example:

{{#if: {{{x|{{{y|}}}}}} | '''{{{x|{{{y|}}}}}}'''. I repeat, {{{x|{{{y|}}}}}}.}}

In many cases, I would greatly prefer to simplify the reuse of {{{x|{{{y|}}}}}}, for clarity, for ease of typing, and for making it more difficult to miss or to screw up. So, I'd like to do something like the following hypothetical syntax:

{{#set:z|{{{x|{{{y|}}}}}}}}
{{#if: {{{z|}}} | '''{{{z}}}'''. I repeat, {{{z}}}.}}

That is, make a new parameter, z, which was not passed to the page, but nonetheless can be used in the page. Is there a way to do something like this?

1 Answers

There is the extension Variables, but it assumes a certain order of parsing, which will not be the case when pages are parsed with Parsoid.

To guarantee the right order of parsing you can use Lua.

But the simplest way will be to create a new template, taking only one parameter and to call it from the original one.

Template1:

{{template2| z = {{{x|{{{y|}}}}}} }}

Template2:

{{#if: {{{z}}} | '''{{{z}}}'''. I repeat, {{{z}}}.}}
Related