Wikipedia:TemplateData/Tutorial: Difference between revisions

Content deleted Content added
Okeyes (WMF) (talk | contribs)
Limitations and questions: why do I keep absent-mindedly signing things?
Identifying the parameters: add more descriptive information about templatedata - used a real example
Line 14:
 
This tells the software that everything between the two tags is TemplateData, and should be referenced when the template is used. The TemplateData itself follows a standard layout that identifies the parameters that may be set within the template.
 
===Templatedata===
The templatedata is added to either the template itself, or the /doc documentation page - anywhere that is transcluded into the template will do. In some cases, the main template page will be locked to prevent editing by unauthorized users. In that situation, the templatedata may be added to the /doc page. The link to that page is at the bottom of the main page.
 
Although it may go anywhere on the template pages, some editors enter the data after the descriptive information about the template and before the "See also" section.
 
===Identifying the parameters===
Many templates have parameters, such as dates, urls, article names, numbers or strings. For instance, citation templates have title, urls, publisher, dates and other publication related information.
 
The first step is to determineDetermine what parameters are or may be used in the template. In some cases, it's values within < >, (e.g., in "<nowiki>{{Str left|<string>|<count>}}</nowiki>", it's string and count.) It could also be parameters passed with equal signs. For instance, the <nowiki>{{cite web...</nowiki> template is passed values to complete a citation, such as url=, title=, accessdate=, etc. In some cases theThe template documentation summarizesmay thatsummarize what parameters thatare or are/may be set for the template.
 
===Completing the templatedata information===
The first value in the templatedata section is the description. Use information that you glean from the top of the main or subpage for the template to describe how the template is used and put that information in quotes {" "}.
 
Then, for each parameter used by the template, complete the following "params" information:
:* Enter the parameter being used. For example, per the [[Template:Str left]] information, <nowiki>{{Str left|<string>|<count>}}</nowiki>, the template has two parameters: string and count.
:* Enter the "params" value. In this example, the first parameter entered was "count"
:* Then add the information about each parameter. The label is the descriptive information for the value that should be entered for the value, capitalizing the first character of the label (since it will be the leftmost value in the resulting table). In this case, it is Quantity. Next, enter the description, which is also likely on the main or subpage. The type indicates if it's a number or a string. For required, enter "true" if the value is required for the template and "false" if it is not required. In this case, both count and sub_string are required values.
:* Where there are more than one parameters passed to the template, add a comma after the close bracket, "}," between the parms values.
 
<pre>
<templatedata>
{
"description": "A template to gives the <count> substring of characters from the start of the trimmed string ",
"params": {
"count": {
"label": "Quantity",
"description": "Gives the <count> substring of characters from the start of the trimmed string",
"type": "number",
"required": true
},
"string": {
"label": "Alpha-numeric text",
"description": "The string to be trimmed and counted",
"type": "string",
"required": true
}
}
}
</templatedata>
</pre>
This would display in the template like so:
 
<templatedata>
{
"description": "A template to gives the <count> substring of characters from the start of the trimmed string ",
"params": {
"count": {
"label": "Quantity",
"description": "Gives the <count> substring of characters from the start of the trimmed string",
"type": "number",
"required": true
},
"string": {
"label": "Alpha-numeric text",
"description": "The string to be trimmed and counted",
"type": "string",
"required": true
}
}
}
</templatedata>
<!------------
Let's say that you have a template called "Commons" for linking to a commons category about an article. It has one parameter, and that is the name of the commons category. The TemplateData would look something like:
 
Line 51 ⟶ 108:
}
</templatedata>
------>
 
Once you've written it out, just add it to either the template itself, or the /doc documentation page - anywhere that is transcluded into the template will do.
 
=== What it all means ===