You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MediaWiki Page Forms配置报错:#template_params需在Ship模板中调用

问题:配置MediaWiki Page Forms扩展时触发#template_params错误

问题背景

参考MediaWiki官方文档配置Templates和Forms扩展时遇到错误。

模板(Ship)内容

<noinclude>
{{#template_params:}}
</noinclude><includeonly>
{{#template_display:_format=plain}}
[[Category:Ship]]
</includeonly>

表单(Ship)内容

<noinclude>
这是“Ship”表单。如需使用此表单创建页面,请在下方输入页面名称;若该名称的页面已存在,将进入编辑表单页面。

{{#forminput:form=Ship}}

</noinclude><includeonly>
<div id="wikiPreview" style="display: none; padding-bottom: 25px; margin-bottom: 25px; border-bottom: 1px solid #AAAAAA;"></div>
{{{for template|Ship}}}
{| class="formtable"
|}
{{{end template}}}
</includeonly>

实例内容

{{Ship}}

触发的错误信息

Error: #template_params must be called in the template "Ship".

解决提示

  • #template_params 必须直接在模板页面的有效执行区域调用,不能放在<noinclude>标签内。<noinclude>里的内容仅在查看模板本身时加载,当模板被其他页面调用时不会执行,导致函数无法识别当前所在模板。
  • 修改模板代码,将{{#template_params:}}移出<noinclude>:
    示例1(仅在模板被调用时执行参数定义):
    <noinclude>
    模板说明内容
    </noinclude><includeonly>
    {{#template_params:}}
    {{#template_display:_format=plain}}
    [[Category:Ship]]
    </includeonly>
    
    示例2(在模板页面和调用页面都能识别参数):
    {{#template_params:}}
    <noinclude>
    模板说明内容
    </noinclude><includeonly>
    {{#template_display:_format=plain}}
    [[Category:Ship]]
    </includeonly>
    
  • 补充:当前表单未定义任何模板参数,生成的页面只会调用空模板。需在表单的表格区域添加参数输入项,同时在模板中定义对应参数。比如:
    表单修改示例:
    {{{for template|Ship}}}
    {| class="formtable"
    ! 船名
    | {{{field|ShipName}}}
    ! 建造年份
    | {{{field|BuiltYear}}}
    |}
    {{{end template}}}
    
    模板修改示例:
    {{#template_params:ShipName|BuiltYear}}
    <noinclude>
    模板说明内容
    </noinclude><includeonly>
    * 船名:{{{ShipName|}}}
    * 建造年份:{{{BuiltYear|}}}
    {{#template_display:_format=plain}}
    [[Category:Ship]]
    </includeonly>
    

内容的提问来源于stack exchange,提问作者NoonanRosenblum

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 22:03:35