Help:TemplateData/zh

什么是模板数据（TemplateData）？
是一种存储关于wikitext模板及其参数的信息的方式，可以方便可视化编辑器在其模板编辑界面中获取显示，简化使用这些模板编辑页面的流程.

模板信息拓展已在所有WMF维基站点上安装妥当. 如果你自己运营维基站点，那么你需要给它安装Extension:TemplateData.

模板数据语法允许用户向模板（或包含入模板的页面，如文档页）写入小块结构化数据. 模板加上这样的数据之后，就可以在可视化编辑器里妥当显示. “结构化数据”什么的词语听起来很复杂，其实一点都不蓝.

模板数据编辑器
有一个内建工具，可用来简易编辑模板数据.

要使用模板数据编辑器，前往模板页面（或其文档页），点按“编辑”按钮. 在打开的编辑窗口上方，你会看到一个写着“”的按钮： 点击这个按钮就可以进入编辑模板数据的图形化工具. 您可借助编辑器加入模板数据及设置常用属性. 如果你编辑的页面已有一块模板数据，则会被编辑器自动载入显示. 在第一个输入框内，您可添加或更新模板的纯文本概述. 接下来，您可以使用“加入推荐的参数”和“加入参数”按钮，记录模板诸个参数的名称和属性.

你可以列出参数的名称（必填，大小写敏感）、任意多个别名、显示时使用的文字标签（推荐）和展现给用户的描述. 你也可以提供一个使用参数的例子. 在“类型”选单中，你可以选择这个参数应接受的内容，例如字符串（纯文本输入）、页面（页面链接）或日期. 如果模板在某项留空时会出错，请将其标为“必填”；如果参数十分常用或推荐使用，请将其标为“推荐”. “移除参数信息”这个按钮会从模板数据中删掉此条参数的信息. When you are finished documenting each of the parameters, click "Apply" to insert the pre-formatted TemplateData into the open editing box. You must still save the page, using the normal "Save" button underneath the editing window.

Caution: The TemplateData editor will place TemplateData on either the template page or on a documentation subpage. You determine where the TemplateData will be added by opening (editing) the page that you want the TemplateData to be placed on. However, if multiple TemplateData blocks are placed on the same template, then only one of those TemplateData blocks will be used. If there is already TemplateData on a page, then you need to edit the page where the TemplateData was previously placed to avoid accidentally creating multiple blocks of TemplateData.

局限及疑问

 * 缺失功能 — TemplateData is very much an example of tool that was made available with few features, in hope that users would help to guide development of features that they desired. If you'd like to request new features for TemplateData, please let us know.
 * 模板显示延迟 — After adding TemplateData to a template, the metadata should be visible immediately when the template is opened in VisualEditor. However, it is possible that it will take several hours before the metadata will show. You can force an update by making a null edit to the template page itself (not the documentation subpage). To perform a null edit, open the template page for editing, and save the page without making any change and without adding any edit summary.
 * 现有问题 — 现有问题（臭虫）和特性请求可在Wikimedia错误追踪系统找到.

模板数据的位置
模板数据应该位于其描述的页面上，或包含入之. 在模板中，其一般应包裹于标签中. On normal page rendering, it displays autogenerated documentation as shown in #Example.

模板信息的结构
模板數據的结构基於「JSON」標準. 所有的模板信息内容都为纯文本（没有wikitext链接等）.

首先要在模板的任意位置打出一对 标签，就像这样：

這將能讓系統知道在兩個標籤之間的內容為模板數據，當模板被使用時即可調出其中的數據資料. 而模板數據的內容有固定的格式，將被用來列出可在模板中使用的參數.

范例
The descriptions inside TemplateData follow a standard layout; let's say that you have a template called "Commons" for linking to a Commons category about a topic. It takes one mandatory parameter: the name of the category on Commons. The TemplateData would look something like this:

This would display, in the template, like so:

{   "description": "A template for linking to a commons category about an article", "params": { "1": {           "label": "共享资源分类", "description": "要链接到的共享资源分类. ", "default": "Category:CommonsRoot", "type": "string", "required": true }   } }

描述和参数
Once you're done, hit "save". If you've made errors, it will not let you save (which is disruptive, but means you can't break anything). Should you run into errors, explain on the feedback page what you were trying to do, and we will be happy to help.

Note that each bit of information is enclosed in quotation marks (except for  and  ), and separated from the next bit by a comma (unless it's the last one).

参数别名
Some templates allow a same parameter to have different names.

For example,  could also be written as   or.

To add this information to TemplateData, you simply need to add the aliases to the parameter's information:

自动值
You can specify an "autovalue" for a parameter. When users add the template to a page, this value will be added automatically. For example, many clean-up templates need to have the date added; if you specify an autovalue for the template's date parameter, then the date will be filled in automatically.

To add this information to TemplateData, simply add the autovalue to the parameter's information. You will probably want to use  to make the values stick:

多个参数
If you have multiple parameters, just repeat each section (starting from the "1" tag) and fill it out as you see fit. Note that if a template has multiple parameters, you need to separate them with a comma in the templatedata, like so:

类似参数
在一个有着多个参数的模板中，经常有参数互相雷同、同属一类的情况. 此时，你只需要完整指定第一个的属性，而让其余的某类参数“集成”第一个的属性.

空白样板
You can copy the blank boilerplate below to add new TemplateData to a template. Only the most common tags are included.

其它工具

 * TemplateDataEditor — A user script that makes the process of adding TemplateData easier. It currently exists in French (contains English, Italian, Japanese and Korean translations), and can easily be translated into other languages.
 * TemplateData Wizard — A tool that generates TemplateData through an interactive interface.
 * Skeleton TemplateData generator — A tool that reads the source wikicode of a template, tries to find all the parameters used and outputs a skeleton document with the parameters listed.
 * JSONLint — A tool that allows you to validate manually-written JSON to help find errors in the syntax.
 * List of all templates with TemplateData on this wiki
 * With dewiki template TemplateData template data is shown in a box, and the template is added to a category of templates with template data