Module:Unsubst/doc: Difference between revisions

Content deleted Content added
m Reverted 1 edit by 152.36.189.167 (talk) to last revision by Pppery
(28 intermediate revisions by 21 users not shown)
Line 1:
<!-- Categories where indicated at the bottom of this page, please. -->
{{high-risk|all=pages=yes}}
 
{{High-risk|2,200,000+}}
{{Module rating|protected}}
 
Maintenance templates, such as {{tl|Citation needed}} or {{tl|Refimprove}}, should never be substituted. A trick to avoid that is to make a template substitute to its transcluded form. This module implements that trick.
Helper module to facilitate a substituted template transform into a template transclusion.
 
Infoboxes should use [[Module:Unsubst-infobox]], as should any other templates with parameters listed in block format by default.
Maintenance templates, such as {{tl|Citation needed}} or {{tl|Refimprove}}, should never be substituted. A trick to avoid that is to make a template substitute to its transcluded form.
 
=== Usage ===
Line 12 ⟶ 11:
To turn a template into a self-substituting template, wrap the existing template code with:
<pre>
{{ {{{|safesubstSAFESUBST:}}}<noinclude />#invoke:Unsubst||$B=
 
[ ... existing template code ... ]
Line 19 ⟶ 18:
</pre>
 
The wikitext to display when not substed must be given as "$B". All other parameters passed to the #invoke will be copied to the generated template invocation as default values. If the value of any of these default parameters is "<code>__DATE__"</code>, that value in the generated template invocation will be the current month and year.
 
Some templates have a &lt;{{tag|noinclude&gt;|o}} but no matching &lt;/{{tag|noinclude&gt;|c}} at the end of the template. In such cases the missing &lt;/{{tag|noinclude&gt;|c}} must be added before the ending <code>{{))}}</code>.
 
==== Advanced ====
 
<pre>
{{ {{{|safesubstSAFESUBST:}}}<noinclude />#invoke:Unsubst||$params=[ parameters ]|$aliases=[ aliases ]|$flags=[ flags ]|$B=
 
[ ... existing template code ... ]
Line 39 ⟶ 38:
Parameter {{para|$flags}} can be used to modify other facets of the module's behaviour; entries are comma-separated. Valid flags are <code>override</code> (allows parameters in the #invoke: to take precedence over parameters in the original template invocation); <code>keep-whitespace</code> (prevents whitespace from being trimmed from unnamed parameters); and <code>remove-empty</code> (removes empty parameters).
 
These parameters can be manipulated using parser functions to provide more complicated options (note that in the parameters any parser function, or template or module invocation, should also have <code>{{(((}}{{!}}safesubst<nowiki>SAFESUBST:{{)))}}<noinclude /></nowiki></code>).
 
Parameter {{para|$template-name}} will override the subst'd templates name with the template name assigned to this parameter.
 
=== Example ===
Consider a template Template:Example containing the following code:
<pre>
{{ {{{|safesubstSAFESUBST:}}}<noinclude />#invoke:Unsubst||foo=bar |date=__DATE__ |$B=
 
[ ... Template code goes here ... ]
Line 54 ⟶ 55:
! Original !! Result
|-
| <nowiki>{{subst:tlsc|example}}</nowiki> || <nowiki>{{tlc|Example|foo=bar|date{{=</nowiki>}}{{#time:F Y}}}}
|-
| <nowiki>{{subst:tlsc|example|foo{{=}}X}}</nowiki> || <nowiki>{{tlc|Example|foo{{=}}X|date{{=</nowiki>}}{{#time:F Y}}}}
|-
| <nowiki>{{subst:tlsc|example|baz{{=}}X}}</nowiki> || <nowiki>{{tlc|Example|foo=bar|baz{{=}}X|date{{=</nowiki>}}{{#time:F Y}}}}
|-
| <nowiki>{{subst:tlsc|example|date{{=}}January 2001}}</nowiki> || <nowiki>{{tlc|Example|foo{{=}}bar|date{{=}}January 2001}}</nowiki>
|}
 
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox other||
| <!-- Categories below this line, please; interwikis at Wikidata -->
[[Category:Wikipedia metatemplates]]