說明:模板資料

![]() |
注意:當您編輯本頁面時,即同意以CC0協議授權您的貢獻。您可以在公有領域说明页面找到更多信息。
|
![]() |
TemplateData 是一个扩展,用于存储与wikitext模板相关的信息和参数,并使其可用于编辑界面,可以在模板编辑器中检索及呈现--所有这些都有助于用户在页面上添加和编辑模板。
自2019年4月起,模板数据功能已是維基媒體裏所有Wiki上的所有用戶在添加模板時,默認的用戶體驗的一部分,即使是未註冊的用戶也一樣。 默认的代碼和可视化编辑器此二者,都以某種型式將其納入其中,如同许多脚本、工具軟體和小工具的做法一樣。 如果你想在自己的wiki上也实现这一功能,请安装Extension:TemplateData 。
要将模板数据添加到模板內以供此扩展使用时,需要在模板的文档页面中插入一个小而简单的JSON(會在下文解释)區块。 您可以手动执行此操作,也可以使用模板数据编辑器,这是一个图形用户界面,您可以在模板的「编辑」/「编辑源代码」页面裏访问,此页面在已安装模板数据的扩展的Wiki上。 JSON包含一个模板的参数列表和关于这些参数以及整个模板的信息(详见下文)。
当用户添加某個模板时,那些包含模板数据的模板将在用户界面中显示此信息。 在某些情况下,当您使用编辑器编辑或插入一個指定的模板时,它将改变编辑器的行为方式,讓用户可以更轻松地执行添加某個指定模板所需的步骤。
歷史
模板数据最初是在2013年初开发的,且已考虑到VisualEditor ,当时正处于MediaWiki测试阶段。 可视化编辑器是维基媒体维基的主要的视觉编辑界面,模板数据使其在添加模板时有一个更有用的界面, 它立即被可视化编辑器正式支持。 从2013年到2016年,随着可视化编辑器作为默认功能被推广到各个主要的维基媒体的wiki中,模板数据也成为了它们的一部分。
2016年12月,可视化编辑器界面可用于编辑源代码,作为是一项测试的功能。 这被称为是2017 維基文本編輯器 。 这首次将模板数据的特点带到了源代码编辑中。
2018年3月,Sam Wilson开发了扩展:模板精灵 ,这是默认的维基媒体源码编辑器WikiEditor (也就是2010年的wikitext编辑器)的GUI模板编辑器扩展,旨在通过使用模板数据的信息使添加模板的过程更容易。 在2019年4月,模板精灵被列为所有维基媒体维基上的2010年维基文字编辑器的默认部分。 这意味着模板数据现在是维基媒体维基上可视化编辑器和源码编辑器的一个默认部分。
添加或编辑模板數據
要添加或编辑模板数据,首先导航到模板的页面,它位于「/Template:Templatename」。
检查目前的状态
在添加或编辑模板数据之前,请检查该模板是否有文档子页面。 然后检查模板是否已经包含模板数据,如果是,它是否位于模板页或文档子页上。
文档子页面
大多数维基媒体维基上的模板有两种主要的方式来存储他们的使用说明和其他不应该包含在实际模板本身的数据,比如模板应该包含的类别:
- 绝大多数模板将使用说明和其他不属于模板页本身的数据放在文档子页上:「/Template:Templatename/doc」。 在这样的页面上,{{Documentation }}的模板将所有的/doc页面的内容都转录在模板页面上,使模板的源代码更加简洁。
- 少数模板页面在模板的主页面上保留了该信息。 在这些页面上,你可以通过寻找
<noinclude>
标签之间出现的{{Documentation|content=
来发现它。
不同的wiki可能会以不同的方式呈现这一切。
極其罕见的情況,即使你已经检查了上述所有内容,主模板页面仍然包含著文档;
就像这里,一个用户已經在「{{Documentation|
」和 「|content=
」之间添加一个自定义的/doc页面标题,然后又在「|content=
」之后添加内容。
你也可以在页面底部寻找类似这样的通知:「上述文档是从Template:Templatename/doc中转录的」。
没有文档子页面的模板
如果一个模板没有文档子页,就创建它并将模板的文档移到那里(或一个占位符)。 然后你可以把模板数据添加到文档子页。
创建子页面并移动文档
要创建文档子页,在主模板页面上点击「编辑」/「编辑源代码」;寻找<noinclude>
的标签及其内容(通常在底部)。
它应该看起来像这样:
<noinclude>
{{Documentation|content=
==使用==
关于使用情况的信息。
==示例的更多标题==
示例的更多內容
[[Category:Example category]]
[[Category:Example category 2]]
}}
</noinclude>
你可能也发现它已经包含了模板数据。 如果是这样,它看起来会像这样:
<noinclude>
{{Documentation|content=
...
<templatedata>
{
"description": "",
"params": {
"1": {
"label": "示例的参数",
"description": "示例的参数描述",
"type": "string"
}
}
}
</templatedata>
</noinclude>
选择「|content=
」之后、「</noinclude>
」之前的所有内容,并将其剪切到剪贴板上或保存在一个临时文件中。删除「|content=
」,只留下以下内容。
<noinclude>
{{Documentation}}
</noinclude>
保存模板页面。
现在,要创建新的子页面,请看你的浏览器的地址栏,在URL的末尾加上/doc。 按↵ Enter,然后选择创建一个新页面的选项。
如果这个wiki有一个{{Documentation subpage }}的通知模板,把它加在新页面的顶部。 你也可能希望添加其他模板,例如{{Purge button }}或{{Purge }}的链接(如果有关的wiki支持的话)。 查看元維基:帮助:模板文档获取更多信息
插入你在前面的文本中剪切或保存的文本(如果有的话,是在通知模板的下面)。
用<includeonly>
标签包裹任何类别,使它们只适用于模板的主页面:
<includeonly>
[[Category:Example category]]
[[Category:Example category 2]]
</includeonly>
许多的wiki都有一个{{Sandbox other}}
的模板。
如果你要编辑的模板很可能存在沙盒版本(位于 「Template:Templatename/sandbox」),请在此使用该模板,以防止类别应用于沙盒页面:
<includeonly>{{sandbox other||
[[Category:Example category]]
[[Category:Example category 2]]
}}</includeonly>
最后,发布该页面。
现在你可以使用#方法中所描述的教導在文档子页上添加和编辑模板数据。
在主模板页面上添加和编辑模板数据
如果你不能创建/doc页面,你可以按照#方法中的教導,在模板的主页面添加和编辑模板数据。
如果一个模板有一个文档子页,则同时检查主页面和文档子页是否存在模板数据(<templatedata>
标签后面是一个大括号内的数组:{}
)。
另一種擇,TemplateData扩展可以幫你执行这一检查。 在任何一页上点击「编辑」或「编辑源代码」。 如果模板在任何一个页面上已经有了模板数据,你会在页面的顶部看到一个黄色的通知,上面写着的,不是這個:
- 请注意:关联页面“[[Template:模板名/doc]]”上已存在模板数据代码块。
就是這個
- 请注意:关联页面“[[Template:模板名]]”上已存在模板数据代码块。
如果模板在其文档子页上有模板数据。
如果该模板在其文档子页上有模板数据,这是你应该编辑的页面。
你可以通过点击位于标题「模板文档」(或类似的)之后的 "[编辑] "来实现,或者,如果你已经在/doc页面上,点击顶部的「编辑」或「编辑源代码」。
按照#方法的指导,添加或编辑模板数据。
如果模板在其主页面上有模板数据
如果模板在其主页面上有模板数据,你再次有两个选择:
- 要麼,你可以移动到它的文档子页。这是首选方案。
- 要麼,你可以在主模板页面上编辑它。
将模板数据移至文档子页
要做到这一点,请在主模板页面上点击 「编辑」/「编辑源代码」,并寻找<templatedata>
的标签,将其包在<noinclude>
的标签中。
它应该看起来像这样:
<noinclude>
{{Documentation}}
<templatedata>
{
"description": "",
"params": {
"1": {
"label": "示例的参数",
"description": "示例的参数描述",
"type": "string"
}
}
}
</templatedata>
</noinclude>
只把<templatedata>
的标签和它们的内容从代码中剪掉,然后保存页面。
接下来,通过点击位于标题「模板文档」(或类似)之后的"[编辑]"来编辑文档子页。
输入一个标题,如「模板数据」,然后在其下方粘贴模板数据。
你现在可以根据#方法的指导编辑模板数据。
在主模板页上编辑模板数据
If you do not wish to move the template data to the /doc page, you can edit it on the main template page. See #Methods for how to edit template data.
If the template does not yet have template data but has a doc subpage
If the template does not yet have template data, you should add it to the documentation subpage.
Do this by clicking the "[edit]" located after the heading " Template documentation" (or similar), or, if you are already on the /doc page, by clicking "编辑" or "编辑源代码" at the top.
Type a heading, like "Template data", then add it beneath this heading.
The section #Methods explains how to add template data.
方法
模板數據編輯方法
This is a simple way to add or edit template data, recommended for less experienced users.
模板数据编辑器是一个图形化的编辑器,可用来添加或编辑模板数据。 It is part of the TemplateData extension, available on any template's page (or documentation subpage) by clicking "编辑" or "编辑源代码".
After clicking "编辑" or "编辑源代码", you will see a button above the editing area and page title that says "编辑模板数据".
點擊該按鈕就可以進入模板數據編輯器。 如果您所在的頁面已經包含了模板數據,則會自動顯示在這裡。
Features in the above window:
- The top item chooses the language of the interface text. It allows you to enter text content in multiple languages, displayed to users based on their settings in Preferences, not based on the wiki's language; different wikis have entirely different template databases.
If no language template data exists, the interface will only offer users the wiki's own language, but users can click "添加语言" to add more inputs. The language code is displayed in brackets next to the parameters to which it can be applied, such as descriptions and labels.
- The next item is the template description. This is the description of the template as a whole; it's shown to users in numerous places in the template editors while adding a template. This parameter and its effects are outlined here.
- The third item controls the wikitext formatting of the template. This parameter determines how the wikitext will be laid out when the user clicks "应用", the two main types being
"inline"
(on one line) and"block"
(on new lines). This parameter and its effects are outlined here.
- If the user chooses "自定义", they can enter wikitext under "自定义格式字符串" according to rules outlined here, in order to create a custom layout for the template when the user clicks "应用".
- The fourth item configures a template's parameters.
If parameters have already been defined in template data, this area displays them in a list. If the template's source code specifies parameters for which no template data exists, you may see a button labeled "添加2个推荐的参数". The editor extracts these suggestions from the template's source code by looking for {{{parametername}}}
or {{{parametername|}}}
. Clicking "添加2个推荐的参数" will add these parameters using their names as defined in the source code. A green notice will also appear at the top, for example, "2个新参数已导入:names of parameters".
- At the bottom of the window you see an "添加参数" button. This allows you to add a parameter manually with a custom name.
Continue to the next step by clicking any one of the parameters in the list. This will allow you to edit that parameter's info.
All of these features and their effects are outlined in the section #Within a parameter's name.
- The template data editor will not allow you to change a parameter to a blank "名称".
- Clicking "移除参数信息" will delete the parameter and all its information from the template data. You can't retrieve or undo this in the template data unless you click "X" afterwards. You can undo any changes made after clicking "应用" by hitting Ctrl+Z.
- Exiting the template data editor after making changes prompts you to confirm that you want to discard your changes.
When finished, click "应用".
This will automatically insert the template data at the bottom of the page before the </noinclude>
tag; or, if already present, it will be updated with the new information without changing its position.
The template data text will also be selected when you click "应用".
The template data editor creates a "paramOrder"
parameter at the bottom of the template data (or updates it if it already exists).
"paramOrder"
contains the current template data parameters in the order in which they were displayed by the template data editor.
You can change the "paramOrder"
by dragging the parameters up and down in the template data editor using the three horizontal bars on the left.
"paramOrder"
and its effects are described here.
After this, click "保存" to save your revision of the page.
手动方法
You can also add or edit template data manually.
模板数据的结构基于JSON标准,但你无需了解JSON即可知道如何编辑模板数据。
Template data follows a few very simple rules and accepts only a few dozen possible predefined parameters and values, typically following a "parameter": "value"
format.
Adding template data manually
Considerations:
- If you're adding template data on a template's documentation subpage (recommended), you may add it anywhere on the page; check to see if your language's Wikipedia has a preferred location for it. For example, on the English Wikipedia, template data is typically near the bottom of the documentation page; on the German Wikipedia, it is typically at the top.
- If you're adding template data on a template's main page (not recommended; see #Prior checks), you must make sure to place it inside the
<noinclude>...</noinclude>
tags.
Click "编辑" or "编辑源代码" on the respective page, then move to the place in the page where you intend to add template data and write a heading: "Template data".
Many wikis have a {{TemplateData header}} template that adds a short notice regarding template data. If your wiki does, add it after the heading.
To start adding template data, type an opening and closing <templatedata>
tag and a pair of curly brackets on new lines, with an empty line between them:
<templatedata>
{
}
</templatedata>
Next, add an indent on the empty line between the two curly brackets, and start adding parameters. Details for the parameters can be found at #Template data parameters. Most are optional; some are highly recommended.
Parameters can be in any order, but what follows is the order that best conforms to template data documentation and makes the content easiest to use for editors:
<templatedata>
{
"description": "",
"format": "",
"params": {
"parameter1": {
"aliases": ["",""]
"label": "",
"description": "",
"type": ""
}
},
"paramOrder": [
""
]
}
</templatedata>
Make sure the parameters, for example, in the "params"
object, remain inside that object; otherwise you will trigger an "意外的属性“propertyname”。" error when you try to save.
示例
Here is some example template data for a hypothetical cleanup template. Such a template would display a notice and place the page into a dated category based on the month and year entered. The notice might also contain a link to a talk page section. The template data would look something like this:
<templatedata>
{
"description": "Use this template to indicate that an article is in need of cleanup.",
"format": "inline",
"params": {
"date": {
"label": "Month and year",
"description": "The month and year that the template was added",
"type": "string",
"autovalue": "{{SUBST:CURRENTMONTHNAME}} {{SUBST:CURRENTYEAR}}",
"example": "January 2013",
"suggested": true
},
"reason": {
"aliases": ["1"],
"label": "Reason",
"description": "The reason the article is in need of cleanup",
"type": "string"
},
"talk": {
"aliases": ["talksection"],
"label": "Talk page section",
"description": "The section of the talk page containing relevant discussion",
"type": "string"
}
},
"paramOrder": [
"date",
"reason",
"talk"
]
}
</templatedata>
The corresponding template data documentation would display as follows:
Use this template to indicate that an article is in need of cleanup.
Parameter | Description | Type | Status | |
---|---|---|---|---|
Month and year | date | The month and year that the template was added
| String | suggested |
Reason | reason 1 | The reason the article is in need of cleanup | String | optional |
Talk page section | talk talksection | The section of the talk page containing relevant discussion | String | optional |
描述和参数
All available template data parameters are listed below with a description and example. They are also listed in more technical detail at Extension:TemplateData#Format.
- This information is current as of November 2021 and may change if new parameters are added or the template editing interfaces get updates to support existing parameters or treat certain parameters differently.
- Wiki markup will not work in descriptions or labels. They are strictly plain text strings.
- New lines ("
\n
") in descriptions, labels, examples or defaults will not show in any of the main editors (TemplateWizard, the visual editor or the 2017 wikitext editor), even though they show in the auto-generated template data documentation. They are replaced by a null string in input forms and by a space elsewhere.
Parameter | Description | Example |
---|---|---|
description |
第一项是 Effects On the template documentation page, the description will show in plain text below the "Template data for [template name]" subheading. In all main editors (VisualEditor , the 2017 維基文本編輯器 and the 扩展:Wiki编辑器 with TemplateWizard), the description shows in two main instances:
In the visual editor and 2017 wikitext editor, the description gets truncated to about 50 characters under each search suggestion, followed by a "...", but the whole description shows in the main template editor window. Both are shown in grey text. In the main template editor window, descriptions longer than four lines (about 540 characters) are provided a separate scrollbar, and they are shown in black text. If not specified If the description parameter does not exist or is not specified, the text "无描述。" will be displayed in the template data documentation below the "Template data for [template name]" subheading. Additionally:
|
"description": "用于链接到贡献资源分类",
|
format |
接下来是 This parameter is not required, but it is recommended. The default behavior when this parameter is not provided is preserving the existing formatting for existing parameters, or inline formatting for newly added parameters and templates. Effects Inline: ( When inserted, the template will lay its wikitext out on a single line with no white space between elements, like so:
Block: ( When inserted, the template will distribute its parameters each on a new line, with single spaces between each element, like so: {{Foo | bar = baz | qux = quux }} Custom formatting: Alternatively, if the parameter is set to a custom string of wikitext, as per the rules listed at #Custom formats, the template will lay its wikitext out as per the given wikitext. |
"format": "inline"
|
params |
It should contain the name of each parameter followed by a set of template data sub-parameters listed in #Within a parameter's name. 如果有多个参数,在每个参数对象之间加一个逗号,但不要在最后一个大括号后加一个逗号(见示例)。 |
"params": {
"parameter1": {
... // parameter info
}, // 注意此处的逗号
"parameter2": {
... // parameter info
}, // 以及此处
"parameter3": {
... // parameter info
} // but not here
}
|
paramOrder |
The How to use Add the parameter The parameters need not be on new lines (they may be written as We recommend you place You must include every parameter mentioned in the template data; otherwise a "未找到必需的属性“propertyname”。" error will show. If not specified Without With other parameters In the 2010 wikitext editor with TemplateWizard:
In the visual editor and the 2017 wikitext editor, |
"paramOrder": [
"date",
"reason",
"talk"
]
|
在参数内
Parameter | Description | Example |
---|---|---|
参数名称 |
For example, in a template's source code, You may also see parameters named
Note: a user can still force the use of How to use Each of these "参数名称" objects should contain all of the information about the parameter, in the form of more template data parameters. These are listed in the following section, Within a parameter's name. |
"1": { // 参数名
... // 此处为参数信息
}
|
在参数名称中
Parameter | Description | Example |
---|---|---|
aliases |
The optional
or
This means that if the user inserts either of these parameters with a value, they will perform the same function. Literally, it translates to, "Value of parameter1. If parameter1 doesn't exist or have a value: value of parameter2." In the second case, it also means, "If parameter2 doesn't exist or have a value: no value." To insert the |
"aliases": ["1", "talk", "talksection"],
|
inherits |
To use this parameter, type |
"params": {
"话题1": {
"label": "话题",
"description": "一个在该消歧义页面被提及的话题",
"type": "string"
},
"话题2": {
"inherits": "话题1"
},
"话题3": {
"inherits": "话题1",
"label" : "A different label"
}
}
|
label |
接下来是 |
"label": "Month and year",
|
description |
这里, |
"description": "The month and year that the template was inserted",
|
type |
See the #Type parameter section. |
|
default |
Some template parameters have a default value; the value is used unless overridden by the user.
The Effects In all main editors (the visual editor, the 2017 wikitext editor and the 2010 wikitext editor with TemplateWizard), the With other parameters In all main editors (the visual editor, the 2017 wikitext editor and the 2010 wikitext editor with TemplateWizard), if |
"default": "Category:CommonsRoot",
|
autovalue |
A parameter can be assigned an This value can be overwritten by the user in the template editor. With other parameters In all main editors (the visual editor, the 2017 wikitext editor and the 2010 wikitext editor with TemplateWizard), |
"autovalue": "{{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}"
|
example |
The Effects In all main editors (the visual editor, the 2017 wikitext editor and the 2010 wikitext editor with TemplateWizard), this property is displayed below the parameter description (and below the With other parameters In all main editors (the visual editor, the 2017 wikitext editor and the 2010 wikitext editor with TemplateWizard), |
"example": "January 2013",
|
required |
接下来是 它决定了填写给定的参数对模板来说是否是强制性的。 Effects This status has several effects in the visual editor and the 2017 維基文本編輯器 :
In the 扩展:Wiki编辑器 with 帮助:扩展:模板助手 , as in the other editors, it displays the parameter automatically when a user inserts the template, but the parameter cannot be removed using this or any editor. It also does not display "必填字段。" in the parameter description; rather, it lists the parameter on the side under "必需参数". Other than this, it generally behaves the same as in the other editors, except that the prompt says that the input doesn't "match the expected format". With other parameters In the visual editor and the 2017 wikitext editor, the |
"required": true
|
suggested |
接下来是 Use Effects In the visual editor and the 2017 維基文本編輯器 , it causes the parameter to automatically show up when a user inserts a template. If the parameter has an autovalue set, this will also automatically be in the parameter's input box. It has no other effect and doesn't show any additional text or warnings. In the 扩展:Wiki编辑器 with TemplateWizard, it does not place the parameter in the template automatically but instead causes it to be listed on the side under "推荐参数". The user can then click a "+" next to the parameter to add it to the template. With other parameters The |
"suggested": true
|
deprecated |
最后,有 这是一个不应再被使用的参数的状态,但仍然暂时存在。 这可能是因为此模板的使用正在从一套参数被移动到另一套。 Effects The effect of this parameter in the visual editor and the 2017 wikitext editor is that a grey exclamation mark shows next to the parameter's label when it is inserted, and in the parameter's information tooltip, the grey, italic text "字段已弃用。deprecation reason" is shown below the parameter description. It does not affect the functionality or usability of the parameter or show any additional warnings. Despite the fact that it can take a string, as of January 2020 none of the main editors (the visual editor, the 2017 wikitext editor or the 2010 wikitext editor) display the contents of the string anywhere to users.
Inputting a string has the same effect as In the 2010 wikitext editor with TemplateWizard, setting this value as With other parameters If you set both this and If you set both this and In the 2010 wikitext editor with TemplateWizard, |
"deprecated": "Please use 'publicationDate' instead."
|
suggested values |
The parameter property
Other types (file, page, template, user, date, boolean, URL) are not currently supported because they have special functionalities in the visual editor already, such as autocomplete, which would interfere with the drop-down menu for suggested values in the visual editor. Editing template data as JSON in wikitext To add suggested values to any parameter type, add the new property "suggestedvalues" to the parameter in JSON. The “suggestedvalues” attribute must be a list of strings. Editing template data with the template data editor
Effects Once the values have been added to template data, the visual editor will display them in a combo box (a dropdown into which users can also enter a custom value) for the parameter types listed above. The user selects the desired value by clicking on it. If the list of values is long -- for example, a list of a country’s states -- the user can begin typing in the field, whereupon the list will be filtered to show only values containing the typed text. To change an entered value, the user must simply clear the field, and the full dropdown list will appear again. If the user needs a value not included in the list (for example, "message in a bottle") they can type it in manually. |
"suggestedvalues": [
"Journal",
"Book",
"Newspaper",
"Magazine"
]
|
Note: if neither "required"
, "suggested"
nor "deprecated"
are set as true
for a parameter, its status will show as "optional"
in the template data documentation.
一旦您完成,点击“保存”即可。如果您做出了错误,它将不会让您保存(这或许是破坏,但意思是您不能损坏任何东西)。您应该运行调试错误,在反馈页面介绍您要尝试进行的操作,并且我们将很高兴帮助。
Note that if you are abusing a hack template to dynamically generate template data, it cannot be checked for errors before saving.
请注意:信息的每项都被引号包围(true
和false
除外),且并用逗号与下一项分开(除非这是最后一个)。
类型参数
"type"
参数控制可视化模板编辑器如何解读参数。
In some cases, template editors have been programmed to modify the user interface for a certain parameter according to this template data value, such as to only allow the user to enter valid values that match the specified type.
This parameter does not have any functional effect on the template parameter or its value; it merely controls how template editors see and treat the parameter in editing mode.
How to use
It is used by adding the "type"
parameter, followed by a colon and a space, then adding any of the values listed in the table below in quotation marks.
Example:
"type": "string",
Effects
As of February 2020, only 5 of the 13 type values have visible effects in VisualEditor and the 2017 wikitext editor, while 8 have visible effects in TemplateWizard.
The effects of certain values are likely to change as the template editors get updates to support them. One such effort for VisualEditor and the 2017 wikitext editor is tracked in the Phabricator task T55613. A similar effort to get TemplateWizard to support the boolean value is tracked in T200664.
The currently known effects are listed as follows.
Value | Description | |
---|---|---|
unknown |
The Effects In all main editors (VisualEditor, 2017 wikitext editor and the 2010 wikitext editor with TemplateWizard), | |
string |
The Effects In all main editors (the visual editor, the 2017 wikitext editor and the 2010 wikitext editor with TemplateWizard), | |
line |
The Effects
| |
content |
The Effects
| |
unbalanced-wikitext |
The Effects
| |
wiki-page-name |
The Effects In all main editors (the visual editor, the 2017 wikitext editor and the 2010 wikitext editor with TemplateWizard), | |
wiki-file-name |
The Effects
It has no other visible effect and doesn't prevent a non-file from being inputted. | |
wiki-template-name |
The Effects In all main editors (the visual editor, the 2017 wikitext editor and the 2010 wikitext editor with TemplateWizard), | |
wiki-user-name |
The Effects In all main editors (the visual editor, the 2017 wikitext editor and the 2010 wikitext editor with TemplateWizard), | |
number |
The Effects
With other parameters
| |
boolean |
The Effects As of February 2020, none of the main Wikimedia editors (the visual editor, the 2017 wikitext editor or the 2010 wikitext editor with TemplateWizard) make use of this value. It has no visible effects. With the | |
date |
The Effects
With other parameters
| |
url |
The Effects
required " setting, but it does not warn the user if they attempt to insert the template without a valid URL. It also occurs with any status setting (such as "suggested" " or "deprecated ").
With other parameters
|
自定义格式
When editing the "format"
value, you create custom formats by inputting a set of wikitext symbols using some predefined rules.
{{
- start of the template_
- content (e.g., string, integer or parameter). This underscore serves to indicate the minimum length of a value in characters and can be repeated, like_______
. If this length is not reached, it fills the remaining characters with spaces. This can be used to align all equals signs to a specific position after a parameter (if used with\n
for new lines).|
- pipe (separates parameters)=
- equals sign (precedes the value of a parameter)\n
or pressing the enter key - new line (this will display as↵
in the entry field)\n
to indent new lines)}}
- end of the template
The wikitext should at least meet the minimum of {{_|_=_}}
, otherwise there will be an invalid format string error.
目标 | 格式字符串 | 输出 |
---|---|---|
行内格式 | {{_|_=_}} inline
|
{{Foo|bar=baz|qux=quux}}{{Bar}} |
区块格式 | {{_\n| _ = _\n}} block
|
{{Foo | bar = baz | qux = quux }}{{Bar}} |
No space before the parameter name, each template on its own line | \n{{_\n|_ = _\n}}\n
|
{{Foo |bar = baz |qux = quux }} {{Bar}} |
缩进每个参数 | {{_\n |_ = _\n}}
|
{{Foo |bar = baz |qux = quux }}{{Bar}} |
Align all parameter names to a given length | {{_\n|_______________ = _\n}}\n |
{{Foo |bar = baz |qux = quux |veryverylongparameter = bat }} {{Bar}} |
Pipe characters at the end of the previous line | {{_|\n _______________ = _}}
|
{{Foo| bar = baz| qux = quux}}{{Bar}} |
Inline style with more spaces, must be at start of line | \n{{_ | _ = _}}
|
{{Foo | bar = baz | qux = quux}} {{Bar }} |
Template at the start of a line, indent-aligned parameters, pipe beforehand | \n{{_ |\n _______________ = _}}
|
{{Foo | bar = baz | qux = quux}} {{Bar}} |
空白样板
您可以复制下面的空白样本来向一个模板中添加新的模板信息。只包含最常见的标签。
<templatedata>
{
"description": "",
"params": {
"1": {
"label": "",
"description": "",
"type": ""
},
"2": {
"label": "",
"description": "",
"type": ""
}
}
}
</templatedata>
错误
JSON内有语法错误。/糟糕的JSON格式
These errors occur when saving template data, usually manually edited, with invalid JSON code (duplicate keys/parameters, trailing or missing commas, etc.) in the visual editor or the 2017 wikitext editor.
"JSON内有语法错误。" appears in the visual editor and the 2017 wikitext editor; "Bad JSON format" appears when editing in the template data GUI editor.
These errors can be difficult to detect and come in too many forms to list. The best way to avoid them is to edit template data exclusively with the template data editor; the best way to detect them once they've occurred is to use an external JSON validator, such as JSONLint, which will highlight errors and aid in fixing them.
The 2010 wikitext editor does not check for invalid JSON thanks to an old, unfixed bug (任务T128029). Pages that contain invalid JSON may throw alarming "内部错误" messages. To fix these errors, your best bet is to use a JSON validator (see above).
未找到必需的属性“paramOrder[number]”。
This error occurs if you state a parameter in "params"
that is not stated in "paramOrder"
.
The number in the square brackets refers to the parameter in "paramOrder"
that is missing. It refers to its order in the sequence, but it is one less than its actual position, since "paramOrder"
is an array; 0 is the first one, 1 is the second, etc.
"params": {
"date": { ...
},
"reason": { ...
},
"talk": { ... // <-- This parameter is not stated in "paramOrder", but it should be.
}
},
"paramOrder": [
"date",
"reason"
]
// Error: Required property "paramOrder[2]" not found.
To fix this, make sure all parameters stated in "params"
are listed in "paramOrder"
.
Alternatively, you can remove the "paramOrder"
object to remove this error.
属性“paramOrder[number]”的值无效。
This error occurs if you state a parameter in "paramOrder"
that is not stated in "params"
.
The number in the square brackets refers to the parameter in "paramOrder"
that shouldn't be there. It refers to its order in the sequence, but it is one less than its actual position, since "paramOrder"
is an array; 0 is the first one, 1 is the second, etc.
"params": {
"date": { ...
},
"talk": { ...
}
},
"paramOrder": [
"date",
"reason", // <-- This parameter is not stated in "params", but it should be.
"talk"
]
// Error: Invalid value for property "paramOrder[1]".
To fix this, make sure all parameters stated in "paramOrder"
are listed in "params"
.
Alternatively, you can remove the "paramOrder"
object to remove this error.
属性“params.parametername.required”的类型应为“boolean”。
"suggested": "true" // <-- These quotation marks shouldn't be here.
These are boolean values, not strings, therefore they require no quotation marks.
To fix this, remove any quotation marks around the values true
or false
for these parameters.
属性format应该是…(Property "format" is expected to be ...)
If the "format"
parameter exists but its value is not "inline"
, "block"
or a valid format string, you will see the error message "属性“format”应为“inline”“block”或有效的格式字符串。".
"format": "notinline"
// Error : Property "format" is expected to be "inline", "block", or a valid format string.
To fix this, make sure the value after "format":
equals "inline"
or "block"
and that there no spelling mistakes. Alternatively, if it's wikitext, make sure it contains a minimum of {{_|_=_}}
and that there are no mistakes in the syntax that would normally cause a template to fail, such as duplicate equals signs or missing/duplicate curly brackets; see the section #Custom formats for the syntax for custom formats.
Alternatively, you can remove the "format"
parameter to remove this error.
意外的属性“parametername”。
This error occurs if you state a parameter that does not exist in template data. This is probably due to spelling mistakes.
<templatedata>
{
"description": "",
"format": "inline",
"params": {
"1": {
"label": "",
"descriptino": "", // <-- spelling mistake
"type": ""
}
}
}
</templatedata>
It also occurs if you state a parameter in any template data object that is not a parameter of that object. This may be due to spelling mistakes, or you may have written the parameter of one template data object under another object that it doesn't belong to.
For example, you might have written the parameter "label"
under the root template data object instead of inside "params"
:
<templatedata>
{
"description": "",
"format": "inline",
"label": "", // <-- incorrectly placed parameter
"params": {
"1": { // ↓ it should be in here
"description": "",
"type": ""
}
}
}
</templatedata>
Alternatively, if the unexpected parameter is under a template parameter inside "params"
, you'll see its name after "params.parametername." in the error.
To fix this, make sure there aren't any spelling mistakes in the parameter names, and make sure your parameters are in their correct location. Additionally, make sure you don't state any parameters that don't exist for a template data object. You can check which parameters exist for an object in the section #Template data parameters.
未找到必需的属性“params”。
This error occurs if there is no "params"
object in the template data.
This is a necessary object, as it contains all the details of each parameter, so to fix this error, make sure it's added and that there are no spelling mistakes.
See the section above on how to add the "params"
parameter.
局限及疑问
- 缺失功能 – 模板数据是一个工具的例子,它提供了很少的功能,希望用户将有助于指导他们想要的功能的开发。如果您想要请求模板数据的新功能,请l让我们知道。
- 模板显示延迟 – 将模板数据添加到模板后,在可视化编辑器中打开模板时,元数据应立即可见。但是,可能需要几个小时的时间才会显示元数据。您可以通过对模板页面本身(而不是文档子页面)进行空编辑来强制更新。要执行空白编辑,请打开模板页面进行编辑,并保存页面,“而不进行任何更改,也不添加任何编辑摘要”。
- 现有问题 – 现有问题(bug)和特性请求可在Wikimedia错误追踪系统找到。
其它工具
- 帮助:扩展:模板助手
- A toolbar dialog window for entering template wikitext via an form built from template data.
- TemplateData Wizard
- 一个通过交互式界面生成模板信息的工具。
- Skeleton TemplateData generator
- 一个读取模板源wiki代码的工具,尝试寻找使用的所有参数,并按列出的参数输出纲要文档。
- JSONLint
- 一种允许您验证手动写入的JSON以帮助查找语法中的错误工具。
- 在此wiki上所有带模板数据的模板列表
- 使用dewiki template TemplateData模板数据在框中被显示出来,且该模板被添加到有模板信息的分类当中。
- https://query.wikidata.org/ and Query Helper