Bharatpedia:Transclusion: Difference between revisions

no edit summary
No edit summary
Tags: Mobile edit Mobile web edit Advanced mobile edit
No edit summary
Tags: Mobile edit Mobile web edit Advanced mobile edit
Line 12: Line 12:
* '''<syntaxhighlight lang="wikitext" inline>{{Stochastic processes}}</syntaxhighlight>''' will transclude from the page [[:Template:Stochastic processes]]
* '''<syntaxhighlight lang="wikitext" inline>{{Stochastic processes}}</syntaxhighlight>''' will transclude from the page [[:Template:Stochastic processes]]
* '''<syntaxhighlight lang="wikitext" inline>{{:Stochastic processes}}</syntaxhighlight>''' will transclude from the page [[Stochastic processes]] (an article, in the Main namespace)
* '''<syntaxhighlight lang="wikitext" inline>{{:Stochastic processes}}</syntaxhighlight>''' will transclude from the page [[Stochastic processes]] (an article, in the Main namespace)
* '''<syntaxhighlight lang="wikitext" inline>{{Bhartpedia:Assume good faith}}</syntaxhighlight>''' will transclude from the page [[Bharatpedia:Assume good faith]]
* '''<syntaxhighlight lang="wikitext" inline>{{Bharatpedia:Assume good faith}}</syntaxhighlight>''' will transclude from the page [[Bharatpedia:Assume good faith]]


What will transclude from a page can be controlled with the tags <<nowiki/>noinclude>, <<nowiki/>onlyinclude> and <<nowiki/>includeonly> placed in the source page wikitext. (See [[#Markup|markup]], below.)  The use of tags enables the template to transclude partially, otherwise the double curly braces will always transclude all content.  For ''selective'' transclusion the <<nowiki/>includeonly> parts of the template are named (with the help of [[bp:parser functions|parser functions]]) and that template is then called with the [[Help:Template#Parameters|parameter]] <code>transcludesection=''name''</code>.
What will transclude from a page can be controlled with the tags <<nowiki/>noinclude>, <<nowiki/>onlyinclude> and <<nowiki/>includeonly> placed in the source page wikitext. (See [[#Markup|markup]], below.)  The use of tags enables the template to transclude partially, otherwise the double curly braces will always transclude all content.  For ''selective'' transclusion the <<nowiki/>includeonly> parts of the template are named (with the help of [[bp:parser functions|parser functions]]) and that template is then called with the [[Help:Template#Parameters|parameter]] <code>transcludesection=''name''</code>.


Transclusion events occur every time the page is ''loaded'', when the template is rendered. Another use of the same mechanism is a one-shot ''[[Help:substitution|substitution]]'' of the template call itself by its transcluded source page.  A template call <code>{<nowiki/>{''[[BP:page name#Namespace, pagename, and fullpagename|fullpagename]]''}}</code> with the "subst:" prefix <syntaxhighlight lang="wikitext" inline>{{subst:fullpagename}}</syntaxhighlight> is transcluded once but never again, because the wikitext of that call is replaced (substituted) when its page is ''saved''.  What was a one-time template call becomes the actual wikitext of the template at the time of its call.
Transclusion events occur every time the page is ''loaded'', when the template is rendered. Another use of the same mechanism is a one-shot ''[[Help:substitution|substitution]]'' of the template call itself by its transcluded source page.  A template call <code>{<nowiki/>{''[[WP:page name#Namespace, pagename, and fullpagename|fullpagename]]''}}</code> with the "subst:" prefix <syntaxhighlight lang="wikitext" inline>{{subst:fullpagename}}</syntaxhighlight> is transcluded once but never again, because the wikitext of that call is replaced (substituted) when its page is ''saved''.  What was a one-time template call becomes the actual wikitext of the template at the time of its call.


Transclusion runs in advance of parsing the target page at the HTML layer, so it is possible to emit syntax fragments—even fragments of entity references, such as "&amp;a" and "mp;"—that will parse successfully as combined text in the target page.<!-- tested on an older MediaWiki --> As a design idiom, this tends to violate the principle of least surprise, so it should be used sparingly, when cleaner solution paths do not present themselves. Emitting fragments of template syntax, such as a pair of opening braces, is unlikely to successfully re-parse as template syntax in the target page.<!-- tested on an older MediaWiki --> Even if this worked, it would be unwise to depend upon this as supported behaviour, unless formally documented.
Transclusion runs in advance of parsing the target page at the HTML layer, so it is possible to emit syntax fragments—even fragments of entity references, such as "&amp;a" and "mp;"—that will parse successfully as combined text in the target page.<!-- tested on an older MediaWiki --> As a design idiom, this tends to violate the principle of least surprise, so it should be used sparingly, when cleaner solution paths do not present themselves. Emitting fragments of template syntax, such as a pair of opening braces, is unlikely to successfully re-parse as template syntax in the target page.<!-- tested on an older MediaWiki --> Even if this worked, it would be unwise to depend upon this as supported behaviour, unless formally documented.