Page MenuHomePhabricator

Allow specification of explicit #null: in template markup
Open, Needs TriagePublic

Description

This isn't a high priority issue but, came up when coding a template here: https://en.wikisource.org/w/index.php?title=Template:Ukroadsign/images&action=history

It wasn't possible in the clause for image=@dia to do a simple {{{newno|{{{diagram}}} }}} paramater as certain documentation suggested, because newno is conditionally passed in from a higher level template https://en.wikisource.org/w/index.php?title=Template:Ukroadsign as

{{{newno|}}}

meaning that an empty string "" is generated, rather than what was intended which was that if newno wasn't supplied to the parent it wasn't passed onto the sub template.

It would be nice to have a way of more precisely doing the intended logic which is if {{{newno}}} is unknown to the parent, don't pass it to the sub-template, WITHOUT having to make the {{{newno}}} paramater mandatory in the parent template.

Thusly it would be appreciated if a #null: value could be explicitly specified. In the parent template I can then write

newno={{{newno|#null}}}

which the relevant clause in the called template

{{{newno|{{{diagram}}} }}}

will interpret correctly, applying {{{newno}}} if it's specified, or {{{diagram}}} if it's null or unspecified.

Explicitly specifying nulls in this manner would in some places make it easier to write certain templates or at least debug them.

Event Timeline

Aklapper renamed this task from Allow specifcation of explicit #null: in template markup... to Allow specification of explicit #null: in template markup.Apr 6 2017, 6:57 PM

You can use #if from the ParserFunctions extension:

{{#if: {{{newno|}}} | {{{newno}}} | {{{diagram|}}} }}

That seems easier instead of appling a #null which only developer knows the correct use about.

Umherurrender, Using an if is essentially the code I eventually used as a temporary fix, but that doesn't solve a long term issue, that Mediawiki currently can't easily determine between, not-specfifed values; null values; and specfied but empty values (which is what was occuring in the templates mentioned).

Explicitly marking nulls would be less confusing in the long run, and would reduce the amount of parser function calls needed in very complex templates with a lot of optional parameters.

ShakespeareFan00 lowered the priority of this task from Low to Lowest.

Marking as declined, No Consensus to implement this emerged.

ShakespeareFan00 raised the priority of this task from Lowest to Needs Triage.