FANDOM


48px-Emblem-notice.svg.png

待翻譯頁面

本頁面尚未翻譯完成,歡迎使用者協助翻譯。更多未譯頁面

此擴充功能在Fandom並未預設啟用,但可聯絡Fandom申請使用。

變量值(Variables)擴展功能允許在一个頁面定義變量詞(就像代數中的X一樣),並可於同一頁面上的其他位置再次使用、改變數值等,可能是以稍後計算新的數值並取代舊有的等。

變量值就好比模板般的一樣,只是更能減輕網頁負載和只能於同一頁面上使用,所以不用擔心因為使用了大量的變量而減慢維基的頁面。此擴展功能一併與其他Parser函數使用將能獲得最佳效果。

代入數值予變量詞

#vardefine

  • {{#vardefine:變量A|指定值}}

代入一個指定值變量詞去(該變量詞可以是已經被代入數值或從未代入的)

  • 例如: {{#vardefine:iconwidth|25}} 代入 iconwidth 為 25

#vardefineecho

  • {{#vardefineecho:變量詞|指定值}}

Works exactly as #vardefine, but the affected value is printed.

  • 例如: making iconwidth = {{#vardefineecho:iconwidth|25}}


檢索/取用變量詞中的值

#var

利用以下代碼生成變量詞中的值:

  • {{#var:变量名称}}

如果未被定義為任何值的話,這將只會生成一個空格而不會有任何錯誤訊息

也可以利用以下方法以避免出現該變量詞未被定義或引伸出的錯誤:

  • {{#var:变量名称 |默认值}}

This is equivalent to:

  • {{#if: {{#var:变量名称}} |{{#var:变量名称}} |默认值}}

but it is much shorter and better arranged. Before version 2.0 though, the default value always was expanded. From version 2.0 on the default only gets expanded in case it is actually used.

The value can be used in parser functions, etc.

#varexists

  • {{#varexists:变量名称}} returns 1 if the variable is already defined (also when the value is a void string). If the variable is not defined the return value is void.

#var_final

Experimental new function introduced in Variables 2.0. This function will output the final, last value a variable has at the end of the page rendering. Naturally, the value will be inserted after the parser went over the entire wiki markup, so this function can't be used in other functions, expecting the right value is being used. Example:

  • {{#var_final:变量名称 |default}}

The default value will be used if the variable doesn't exist at the final page rendering stage or if its value is an empty string. The default will be expanded right where the function is used, so the parameter will be expanded, even if it won't be needed.

例子

The ParserFunctions extension must also be installed to use #expr.

计算x = 2*a + b

  • {{#vardefine:x|{{#expr:2*{{#var:a}}+{{#var:b}}}} }}

加入一个至“n”:

  • {{#vardefine:n|{{#expr:{{#var:n}}+1}}}}


另參見

  • Help:Parser函數 -
  • Help:陣列 - Create an array and provide array functions (such as search, split, and sort) and set operations (such as intersect, union and diff)
  • Help:循環 - Provides parser functions for performing loops
  • Help:LoopFunctions - 另一個有關循環Loop功能的擴展功能

帮助及反馈


原文: Mediawiki[英]

除了特别提示,社区内容遵循CC-BY-SA 授权许可。

Fandom may earn an affiliate commission on sales made from links on this page.

Stream the best stories.

Fandom may earn an affiliate commission on sales made from links on this page.

Get Disney+