Module:Unsubst/documentation: Difference between revisions

From The Languages of David J. Peterson
Jump to navigation Jump to search
(Created page with "This module protects templates and modules from being wrongly substituted. == Usage == First, put the following at the beginning of the <code>entry_point</code> function in t...")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 34: Line 34:
<includeonly>
<includeonly>
[[Category:General utility modules]]
[[Category:General utility modules]]
[[Category:Wiktionary modules]]

Latest revision as of 21:20, 18 September 2023

This module protects templates and modules from being wrongly substituted.

Usage

First, put the following at the beginning of the entry_point function in the module:

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

Where "entry_point" should be replaced with the function name. Next, edit the template:

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

The <noinclude/> is optional. The template will substitute into its transcluded form.

To protect the module itself instead of the template, add this at the start of the function instead:

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

Directly in templates

You can wrap the template code in

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

It will work just like unsubst_template above, apart from also generating a transclusion to Module:unsubst. Additionally, it protects templates from being copied and pasted to non-template pages.