跳转到内容

模板:Calculator ifenabled/doc

来自天灾之下:危险连接资料站
wiki>Bawolff2025年1月29日 (三) 00:34的版本 (2 revisions imported from w:en:Template:Calculator_ifenabled/doc: Importing calculator related template to use with Global gadgets system)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

Allows you to detect if the calculator gadget is enabled and provide fallback content for cases where it is not such as when printing. See {{Calculator }} for details on the calculator template system.

Usage

{{calculator ifenabled|enabled=Lets show a calculator widget {{calculator|type=number|size=4}}|disabled=Calculator widgets are not supported}}

Which outputs:

Calculator widgets are not supported

If you add the scoped parameter, then calculators inside the enabled branch do not affect other calculators on the page. There is also a refreshonload parameter to force a refresh on first page load instead of first interaction as usual (this only works if scoped is set). For example:

{{calculator ifenabled|scoped=true|enabled=Lets show a calculator widget: {{calculator|type=number|id=x|size=2}}. The value of X is: {{calculator|type=text|readonly=1|formula=x|default=0|size=2}}.}} The X over here ( {{calculator|type=text|readonly=1|formula=x|default=0|size=2}} ) does not get updated, as the previous {{tl|calculator ifenabled}} is scoped.
{{{disabled}}}
The X over here ( 0 ) does not get updated, as the previous {{Calculator ifenabled }} is scoped.

Template data

Check if the calculator gadget can be used on this page

模板参数

参数描述类型状态
enabledenabled 1

Text to show if calculator is supported

示例值
Some text {{calculator|type=text}}
内容必需
scopedscoped

Mark the calculators inside the enabled branch as isolated from the rest of the page

布尔可选
classclass

Extra css classes for the enabled branch

字符串可选
refreshonloadrefreshonload

Refresh the calculators on the initial page load before any user interaction (required scoped to be set)

布尔可选
disableddisabled 2

Text to show if calculator is not enabled (for example during print)

示例值
Calculator is not supported
内容推荐
class disabledclass disabled

Extra css classes for the disabled branch

字符串可选