Topic on Help talk:TemplateData

Set default value to the value of another template parameter

4
GoodMagician (talkcontribs)

In a template the default value of a parameter can be set to the value of another parameter. For example, parameter 2 can default to the value of parameter 1...

{{{2|{{{1}}}}}}

What is the correct way to represent this relationship in templatedata so that Visual Editor will handle the default properly? I've tried the approach below, but instead of showing the value of parameter 1 the template shows the number 1.


# This approach results in the wrong default behavior 
# when the template is added with Visual Editor

<templatedata>
{
  "params": {
    "1": {…},
    "2": {
      "label": "optional value",
      "description": "if this value is empty, show the value of parameter 1 instead",
      "suggested": true,      
      "default": "{{{1}}}"
    },
    "paramOrder": […],
    "format": "inline"
}
</templatedata>

Clump (talkcontribs)

My interpretation would be to indicate it as an alias.

Jonesey95 (talkcontribs)

Agreed. In the code shown above, 2= is an alias of 1=.

Tacsipacsi (talkcontribs)

However, there are situations where an alias doesn’t work. Imagine a template that links to the English Wikipedia. Its code is

[[w:{{{1}}}|{{{2|{{{1}}} }}}]]

—the first parameter (the article title) is required, while the second (the display text) is optional, and defaults to the article title. The two are clearly not aliases, but the default of parameter 2 is parameter 1. I usually write something like “parameter #1” to default and hope that the human reading it will understand what’s going on. Or describe the situation in description, and leave default empty. But neither of these workarounds is really a solution. Probably there should be a new key (mutually exclusive with default) that contains a parameter name (instead of literal text) the parameter defaults to. Support for this should be implemented in consumers like VisualEditor afterwards, of course.

Reply to "Set default value to the value of another template parameter"