Help:Substitution: Difference between revisions

m
278 revisions imported from wikipedia:Help:Substitution: R to helpspace
m (Reverted edits by 165.225.104.55 (talk) (HG) (3.4.9))
m (278 revisions imported from wikipedia:Help:Substitution: R to helpspace)
 
(40 intermediate revisions by 31 users not shown)
Line 1:
{{short description|Help about using templates}}
{{for|detailed guidance on when to use substitution rather than transclusion|Wikipedia:Substitution}}
{{Wikipedia how-to|H:SUBST}}
Line 8 ⟶ 9:
[[Help:variable|Variable]]s and [[Help:parser function|parser function]]s can also be substituted, meaning that their current value will be recorded permanently on the page – they will not be re-evaluated whenever someone views the page.
 
<ref><ref><ref></ref></ref></ref>==When to use substitution==
Generally speaking, templates are [[WP:transclusion|transcluded]] rather than substituted, although there are some that are specifically designed to be substituted (and may not work if transcluded). Some reasons for substituting templates include:
*making the resulting page independent of future changes to the template
Line 77 ⟶ 78:
[[Help:Guided tours|Guided tours]] can make posts on behalf of users, such as automatically posting the contents of a wiki page onto a talk page. Unlike normal substitution or transclusion, however, this function of guided tours does not respect {{tag|includeonly}} and similar markup. To make recursive substitution work via guided tour posting, you can use the [[m:Help:Recursive_conversion_of_wikitext#Delaying_Template:subst|Delaying Template:subst]] method described on Meta.
 
=== An example of recursion in action ===
=== Examples ===
 
{{Tlf|!}} substitutes to |.
This is an example using the actual [[Template:Like]], and a hypothetical Template:Foo. You are attempting to include the Template:Foo, and indirectly the Template:Like, on a third page through transclusion and substitution. Template:Like displays a like symbol like this: {{Like}}
 
For example, lets say the Template:Foo contained the wikitext <code><nowiki>{{Like}}</nowiki></code>. If you then transclude it, using the wikitext <code><nowiki>{{Foo}}</nowiki></code>, this will transclude the Template:Like as you would expect. But if you use the wikitext <code><nowiki>{{subst:Foo}}</nowiki></code>, when you save it you find the wikitext <code><nowiki>{{Like}}</nowiki></code> substituted rather than the wikitext of the page Template:Like. The substitution has not been recursive.
 
An example of recursion would be if the Template:Foo contained the wikitext <code><nowiki>{{{{{|safesubst:}}}Like}}</nowiki></code>. Now if you transclude it, using the wikitext <code><nowiki>{{Foo}}</nowiki></code>, this will transclude the Template:Like just as before. And if you save <code><nowiki>{{subst:Foo}}</nowiki></code> it will substitute the full actual wikitext of the Template:Like. You have therefore achieved recursive substitution.
 
=== Further examples ===
Note: {{Tlf|!}} substitutes to |.
{| class="wikitable"
|-
! rowspan="2" | ContentsWikitext of {{Tlf|foo}}Template:Foo
! rowspan="2" | When you view <nowiki>[[Template:foo]]Foo</nowiki>,<br />it looks like:
! colspan="2" | The result of <nowiki>{{fooFoo}}</nowiki><br />if included on this page
! colspan="2" | The result of <nowiki>{{subst:fooFoo}}</nowiki><br />if included on this page
|-
! saves as:
Line 99 ⟶ 108:
|&#124;
 
Foo
foo
 
yes
|
<nowiki>{{fooFoo}}</nowiki>
|&#124;
 
Line 133 ⟶ 142:
<nowiki>{{subst:#if: 1 | yes | no}}</nowiki>
|
<nowiki>{{fooFoo}}</nowiki>
|<nowiki>{{subst:!}}</nowiki>
 
Line 159 ⟶ 168:
|&#124;
 
Foo
foo
 
yes
|
<nowiki>{{fooFoo}}</nowiki>
|&#124;
 
Line 212 ⟶ 221:
 
==See also==
* [[User:Valereee/Substitution and transclusion for dummies|Substitution for Dummies]]
* [[m:Help:Substitution]], a longer and more technical help page at Meta
* [[mw:Extension:ExpandTemplates]]
Line 218 ⟶ 228:
** {{tim|last edit}} – example: <span class="plainlinks">[{{fullurl:Special:Contributions|limit=1&target={{urlencode:Example User}}}} last edit]</span>
** {{tim|page history}}
* [[Wikipedia:WikiProject Check Wikipedia#Template programming element|WikiProject Check Wikipedia §&nbsp;Template programming element]] lists articles where templates were substituted rather than transcluded.{{dead link|date=July 2011}} {{link note|note=According to the Wayback Machine, [//web.archive.org/web/20100528224125/http://en.wikipedia.org/wiki/Wikipedia:WikiProject_Check_Wikipedia the last time this link worked] was May 2010. It appears to have been removed since then. Perhaps [https://toolscheckwiki.wmflabstoolforge.org/checkwiki/cgi-bin/checkwiki.cgi?project=enwiki&view=only&id=34 this tools page] may help find articles substituted rather than transcluded?}}
 
{{Wikipedia template messages}}
Line 224 ⟶ 234:
{{Wikipedia technical help|collapsed}}
[[Category:Wikipedia help]]
[[Category:Wikipedia guidelinestemplate for templateshelp]]
 
[[fr:Aide:Modèle#Substitution]]