Wikipedia:TemplateData/Tutorial: Difference between revisions

Content deleted Content added
now in cat:TD tree
clean up
Line 46:
:** The <code>"'''aliases'''"</code> group lets you list other names for this parameter which have been set to work equally well, and its entry is enclosed by a single bracket, i.e., <code>"aliases": [ "2", "Caption", "imagecaption" ]</code>. An alias is an alternative name for the parameter that the template is willing to accept instead of (not in addition to) the primary name. Aliases are not documented in a separate parameter object.
:* The <code>"'''autovalue'''"</code> entry lets you tell VisualEditor and other tools to pre-fill this parameter with a standard value (in wikitext); this text will show up in the parameter box when users edit, and will be added to the template invocation when saved. This may be useful for cleanup templates to automatically set the date the user adds a template. For example, add <code><nowiki>""autovalue": "{{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}"</nowiki></code> as the autovalue to have the relevant date, "{{CURRENTMONTHNAME}} {{CURRENTYEAR}}" automatically added when an editor uses the template([https://en.wikipedia.org/w/index.php?title=Template:Citation_needed/doc&diff=631687918&oldid=628385301 example edit]). Autovalues may be changed by the editor simply by removing the supplied value in the template dialog. Note that this subst-based method [[bugzilla:2700|does '''not''' work]] for any templates that are used inside <nowiki><ref></nowiki> tags, gallery tags, or other extension-specific tags. Whether or not set by the person creating the TemplateData code, this entry, whatever it is, will appear as an entry in the resulting TemplateData table; if not created manually, it will be followed by the word "Empty".
:* The <code>"'''default'''"</code> setting lets you show what the template will do if this parameter isn'tis not set (or is set but left blank); this text will show up as light gray text in the parameter box when users edit, but will not add the value to the template invocation when saved unless the user manually overrides it. Rare. This entry will always appear in the resulting TemplateData table, and if not manually created by the person writing the TemplateData code, will be followed by the word "Empty".
:* The <code>"'''example'''"</code> entry allows you to display an example of an entry that a person might make for this variable, written exactly as a person might type it, character-for-character; if the type of entry has already been set with the <code>"'''type'''"</code> parameter (see below), then the example should reflect this (i.e., if the type has been set to "wiki-page-name" then your example should ''not'' include a prefix like "File:" or "Image:"). Be sure to enclose the entire text of the example with quotes. Obviously, this means the actual example may not contain quotation marks itself. If not created by the person writing the TemplateData code, will be followed by the word "Empty".
:* The <code>"'''type'''"</code>, which controls how the template editor will interpret that parameter. This can be one of a few values, any of which used must be enclosed in double quotation marks:
Line 96:
 
==== Save ====
Once you're done, hit "save". If you've made errors, it will not let you save – which can be a little frustrating, as the resulting error message will not tell you where JSON encountered the first code error, but means you can'tcannot "break" anything or put up a table that is accidentally malformed. If you find you are unable to save because of a code error, some common problems to look for include:
* Is every opening quote (<code>"</code>) matched with a closing quote in the correct place of the code?
* Does a string, such as a description of a parameter, contain a <code>"</code> that is not at the end of the entry? If so, consider replacing it with a <code>'</code>.