Page MenuHomePhabricator

Create short-hand function for {{#var:x|{{#vardefineecho:x| arg }}}}
Open, LowPublic5 Estimated Story PointsFeature

Description

A common known use case of Variables is to accelerate parsing of pages, that transcluded the same template with the same arguments several hundred times before. Variables allow users to cache such data instead of reparsing the concerned code that often. However, to make templates using them work even if they are standalone, the first call of a variable often looks like this;

{{#var:x|{{#vardefineecho:x|{{{1}}}}}}}

If this syntax is used nested, code becomes kind of hard to read and less clear, so I propose the introdunction of a new parser function (maybe called #varfallback), that behaves exactly like #var with the difference that it saves provided default values of variables if the variable isn't defined. It should probably produce an error detectable by #iferror if no value can be set, but this needs further consideration.

This additional parser function would allow this code:

{{#var:Pkmn-typ1|{{#vardefineecho:Pkmn-typ1|{{Id2Typ1|{{#vardefineecho:Pkmn-nr|{{namenr|{{#var:Pkmn-name|{{#vardefineecho:Pkmn-name|{{#titleparts:{{PAGENAME}}|1}}}}}}}}}}}}}}}}

to be written like this:

{{#varfallback:Pkmn-typ1|{{Id2Typ1|{{#varfallback:Pkmn-nr|{{namenr|{{#varfallback:Pkmn-name|{{#titleparts:{{PAGENAME}}|1}}}}}}}}}}}}