MediaWiki:添加到模板时的信息框值
我在 mediawiki 网站上阅读了大量有关模板创建的信息。我还实现了自己的模板。我唯一的问题是,我有一个模板,其中绑定了一个信息框。每当我向信息框中添加新项目时,我希望它反映在所有与其关联的模板的页面上,无论我是否在使用该模板的页面中拒绝了它。我需要它有一个默认值。因此,基本上,当我向信息框中添加某些内容时,使用此模板的每个页面都会自动在信息框中将其视为“默认”,直到它们插入自己的值为止。这是否可能,或者这是 mediawiki 上的模板不能做什么?
我的主要问题是:如何包含 mediawiki 模板并让它显示所有内容,包括未定义的变量?例如,如果将新数据添加到模板中,但尚未“填充”,这将非常有用,这将指示需要插入数据。
更新 2011 年 10 月 14 日 @ 下午 3:30 CST:
这是实际的模板(称为 Template:EmployeeInfo):
{{Infobox
|name = {{{name}}}
|title = {{{title}}}
}}
以及我包含它的方式(页面称为“Employee Drew”):
{{EmployeeInfo
|name = Drew
|title = My Title
}}
现在...如果我要向模板添加一些内容会怎么样,例如,现在模板看起来像这是:
{{Infobox
|name = {{{name}}}
|title = {{{title}}}
|education = {{{education}}}
}}
即使页面“Employee Drew”(和其他页面)仅定义了名称和标题变量,我如何让包含 Template:EmployeeInfo 的每个页面包含“教育”部分?
I've read a bunch of information on mediawiki's site regarding the creation of templates. I've also implemented my own templates. My only issue is, I have a template that has an infobox tied to it. Whenever I add a new item to the infobox, I want it to reflect on ALL pages that have the template tied to it, whether or not I have defied it in the page that uses the template. I need it to have a default value. So, basically, when I add something to the infobox, each page that uses this template, will automatically see it on the infobox as "default" until they insert their own value in. Is this possible, or is this something that templates on mediawiki cannot do?
My main question is: How do you include a mediawiki template and have it show everything, including the undefined variables? This is useful, for instance, if new data is added to the template, but isn't "filled in" yet and this would be an indicator that the data needs to be inserted.
UPDATE 10/14/2011 @ 3:30PM CST:
Here's the actual template (called Template:EmployeeInfo):
{{Infobox
|name = {{{name}}}
|title = {{{title}}}
}}
And the way I include it (page is called "Employee Drew"):
{{EmployeeInfo
|name = Drew
|title = My Title
}}
Now...what if I were to add something to the template, for instance, now the template looks like this:
{{Infobox
|name = {{{name}}}
|title = {{{title}}}
|education = {{{education}}}
}}
How would I get every page that includes Template:EmployeeInfo to include the "education" section, even if the page "Employee Drew" (and other pages) only have the name and title variables defined?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您的 Template:Infobox 正在测试变量是否为空并且不显示该字段?最简单的方法是在 Template:EmployeeInfo 中为 education 变量指定默认值:
I take it that your Template:Infobox is testing that the variable is empty and not displaying the field? The easiest way is to just specify a default value for the education variable in your Template:EmployeeInfo:
您可以使用 ParserFunctions 扩展 来测试 {{{education}}} 是否变量是否为空,如果是,则用任何内容填充信息框。
You can use the ParserFunctions extension to test whether the {{{education}}} variable is empty or not and fill the infobox with anything if it is.
这很旧,但有人可能会发现它很有用。对于未定义的参数,您可以在模板中定义默认值。
例如:{{{name|no name}}}
在这种情况下,如果参数“name”没有定义,模板将输出“no name”。
https://www.mediawiki.org/wiki/Help:Templates#Default_values
This is old but someone might find it useful. For undefined parameters you can define defaults in the template.
For example: {{{name|no name}}}
In this case, if parameter "name" is not defined, the template will output "no name".
https://www.mediawiki.org/wiki/Help:Templates#Default_values