模組:Unsubst/doc

維基詞典,自由的多語言詞典

此頁面為 Module:Unsubst 的說明文件

此模塊可防止模板和模塊被錯誤替換。

用法[編輯]

首先,將以下內容放在模塊中entry_point函數的開頭:

if mw.isSubsting() then
	return require('Module:unsubst').unsubst_template("entry_point")
end

其中"entry_point"應該替換為函數名。接下來,編輯模板:

{{safesubst:<noinclude/>#invoke:...|entry_point|...}}

<noinclude/>是可選的。模板將替換為其被嵌入的形式。

如果要保護模塊本身而不是模板,請在函數開始處添加:

if mw.isSubsting() then
	return require('Module:unsubst').unsubst_module("entry_point")
end

直接在模板中使用[編輯]

您可以將模板代碼包裹在如下代碼中:

{{safesubst:#invoke:unsubst|me|=
...
}}

結果同上述unsubst_template,另外還會生成對Module:Unsubst的嵌入。此外,它還可以防止模板被複製粘貼到非模板頁面。