Help:Template: Difference between revisions

14 bytes added ,  8 June 2021
m
clean up, replaced: Wikipedia → Bharatpedia (7), WP → BP (39)
m (clean up, replaced: Wikipedia: → Bharatpedia: (27))
m (clean up, replaced: Wikipedia → Bharatpedia (7), WP → BP (39))
Line 1: Line 1:
{{short description|Main technical help page on templates}}
{{short description|Main technical help page on templates}}
{{for|lists of commonly used templates|Bharatpedia:Template index}}{{For|a quick introduction to templates|Help:A quick guide to templates}}
{{for|lists of commonly used templates|Bharatpedia:Template index}}{{For|a quick introduction to templates|Help:A quick guide to templates}}
{{Wikipedia how to|H:T|WP:TEMPLATE}}
{{Bharatpedia how to|H:T|BP:TEMPLATE}}
{{Wiki markup}}
{{Wiki markup}}
A '''template''' is a Bharatpedia page created to be included in other pages. Templates usually contain repetitive material that might need to show up on any number of articles or pages. They are commonly used for [[Bharatpedia:Glossary#Boilerplate text|boilerplate]] messages, standardized warnings or notices, [[Help:Infobox|infoboxes]], [[WP:Navbox|navigational boxes]], and similar purposes.
A '''template''' is a Bharatpedia page created to be included in other pages. Templates usually contain repetitive material that might need to show up on any number of articles or pages. They are commonly used for [[Bharatpedia:Glossary#Boilerplate text|boilerplate]] messages, standardized warnings or notices, [[Help:Infobox|infoboxes]], [[BP:Navbox|navigational boxes]], and similar purposes.


The most common method of inclusion is called [[Bharatpedia:Transclusion|transclusion]], where the [[WP:wikitext|wikitext]] of the target page contains a reference to the template, using the {{tnull|{{var|Template name}}}} syntax. Another method is [[Help:Substitution|substitution]], where the content of the template is copied into the wikitext of the target page, just once, when it is saved.
The most common method of inclusion is called [[Bharatpedia:Transclusion|transclusion]], where the [[BP:wikitext|wikitext]] of the target page contains a reference to the template, using the {{tnull|{{var|Template name}}}} syntax. Another method is [[Help:Substitution|substitution]], where the content of the template is copied into the wikitext of the target page, just once, when it is saved.


[[Help:A quick guide to templates]] gives a brief introduction to the subject. There is further help from MediaWiki and Wikimedia at [[mw:Help:Templates]], [[m:Help:Template]], and [[m:Help:Advanced templates]].
[[Help:A quick guide to templates]] gives a brief introduction to the subject. There is further help from MediaWiki and Wikimedia at [[mw:Help:Templates]], [[m:Help:Template]], and [[m:Help:Advanced templates]].
Line 17: Line 17:


==General description==
==General description==
[[File:Introduction to templates on Wikipedia.webm|thumb|A basic overview of how templates work (8-minute video)]]
[[File:Introduction to templates on Bharatpedia.webm|thumb|A basic overview of how templates work (8-minute video)]]


Most templates are pages in the [[WP:Template namespace|Template namespace]], which means that they have titles in the form "Template:{{var|XXXX}}". It is possible, however, to transclude and substitute from any namespace,{{efn|Namespaces from which transclusion is not allowed are specified on a wiki by the variable <code>[[mw:Manual:$wgNonincludableNamespaces|$wgNonincludableNamespaces]]</code>.}} and so some template pages are placed in other namespaces, such as the [[WP:User namespace|User namespace]]. Template pages have associated [[WP:talk page|talk pages]].
Most templates are pages in the [[BP:Template namespace|Template namespace]], which means that they have titles in the form "Template:{{var|XXXX}}". It is possible, however, to transclude and substitute from any namespace,{{efn|Namespaces from which transclusion is not allowed are specified on a wiki by the variable <code>[[mw:Manual:$wgNonincludableNamespaces|$wgNonincludableNamespaces]]</code>.}} and so some template pages are placed in other namespaces, such as the [[BP:User namespace|User namespace]]. Template pages have associated [[BP:talk page|talk pages]].


Templates can contain any desired [[WP:Wikitext|wikitext]], including calls to other templates. They have some limited programming capacities: customizable values (called [[#Parameters|parameters]]); calculation and branchings (using [[Help:Parser functions|parser functions]]); and access to wiki-specific variables ([[Help:Magic words|magic words]]), such as dates, times, and page names. They may also contain [[HTML element|tags]] which define which parts of the wikitext are to be included when the template is transcluded or substituted. This means that the appearance of the template page itself need not be the same as that of the transcluded content (for example, it can contain documentation, categories, etc. for the template).
Templates can contain any desired [[BP:Wikitext|wikitext]], including calls to other templates. They have some limited programming capacities: customizable values (called [[#Parameters|parameters]]); calculation and branchings (using [[Help:Parser functions|parser functions]]); and access to wiki-specific variables ([[Help:Magic words|magic words]]), such as dates, times, and page names. They may also contain [[HTML element|tags]] which define which parts of the wikitext are to be included when the template is transcluded or substituted. This means that the appearance of the template page itself need not be the same as that of the transcluded content (for example, it can contain documentation, categories, etc. for the template).


{{strong|How to do it:}} To transclude a template into an article or page, type {{tnull|{{var|Template&nbsp;name}}}} in the wikitext at the place where the template is to appear. The first letter may be indifferently lower- or upper-case.
{{strong|How to do it:}} To transclude a template into an article or page, type {{tnull|{{var|Template&nbsp;name}}}} in the wikitext at the place where the template is to appear. The first letter may be indifferently lower- or upper-case.


The prefix <code>Template:</code> before the template name is the default one and need not be included. However, for templates stored in other namespaces, the prefix, such as <code>User:</code>, must be specified. To transclude a page in [[WP:mainspace#Namespace|mainspace]], precede its title with a colon, as <code>{<nowiki />{:{{var|Page name}}}}</code>.
The prefix <code>Template:</code> before the template name is the default one and need not be included. However, for templates stored in other namespaces, the prefix, such as <code>User:</code>, must be specified. To transclude a page in [[BP:mainspace#Namespace|mainspace]], precede its title with a colon, as <code>{<nowiki />{:{{var|Page name}}}}</code>.


{{A note}} Attempting to transclude a template that does not exist produces a [[WP:Redlink|red link]], just like linking to any other nonexistent page. Following the link allows one to create that particular template. It is not possible to transclude pages between projects (such as different-language Bharatpedias or MediaWiki)—to use a template on another language project, a copy of the template must be created in that project.
{{A note}} Attempting to transclude a template that does not exist produces a [[BP:Redlink|red link]], just like linking to any other nonexistent page. Following the link allows one to create that particular template. It is not possible to transclude pages between projects (such as different-language Bharatpedias or MediaWiki)—to use a template on another language project, a copy of the template must be created in that project.


==Usage syntax==
==Usage syntax==
Line 34: Line 34:
{{about|template parameters|search parameters|Help:Searching#Parameters|section=yes}}
{{about|template parameters|search parameters|Help:Searching#Parameters|section=yes}}
{{further|m:Help:Templates#Parameters}}
{{further|m:Help:Templates#Parameters}}
{{shortcut|H:PARAMETER|WP:PARAMETER}}
{{shortcut|H:PARAMETER|BP:PARAMETER}}
<!--[[Help:Parameters]] redirects here.-->
<!--[[Help:Parameters]] redirects here.-->
The basic transclusion syntax given above can be extended by the addition of [[parameter]]s, which are used to control the template's output. The syntax for this is
The basic transclusion syntax given above can be extended by the addition of [[parameter]]s, which are used to control the template's output. The syntax for this is
Line 46: Line 46:
The value of a parameter can be the empty string, such as when the pipe or equals sign is followed immediately by the next pipe or the closing braces. This is different from omitting the parameter altogether, which leaves it undefined, although templates are often coded so as to behave the same in both cases.
The value of a parameter can be the empty string, such as when the pipe or equals sign is followed immediately by the next pipe or the closing braces. This is different from omitting the parameter altogether, which leaves it undefined, although templates are often coded so as to behave the same in both cases.


Parameters can be specified (and will do nothing) even if not represented in the template's code. For example, {{para|reason}} is frequently used as a pseudo-parameter to explain briefly in the wikisource why the template was placed.{{efn|Some templates, such as {{tlx|Requested move}}, have code to display {{para|reason}} as visible output; whether to do so is determined on a template-by-template basis.}} Some templates call [[Module:Check for unknown parameters]] to warn the editor if a parameter is being used that is not accounted for in the template's code; this is mostly used for [[WP:Infobox|infoboxes]] and other templates with a large number of complicated parameters, where the presence of an unknown one is usually an unintentional error. If you update such a template to include a new parameter, its call to the module must also be updated to include the new parameter.
Parameters can be specified (and will do nothing) even if not represented in the template's code. For example, {{para|reason}} is frequently used as a pseudo-parameter to explain briefly in the wikisource why the template was placed.{{efn|Some templates, such as {{tlx|Requested move}}, have code to display {{para|reason}} as visible output; whether to do so is determined on a template-by-template basis.}} Some templates call [[Module:Check for unknown parameters]] to warn the editor if a parameter is being used that is not accounted for in the template's code; this is mostly used for [[BP:Infobox|infoboxes]] and other templates with a large number of complicated parameters, where the presence of an unknown one is usually an unintentional error. If you update such a template to include a new parameter, its call to the module must also be updated to include the new parameter.


===Calling===
===Calling===
Line 55: Line 55:
In [[MediaWiki]], the [[wiki software]] that Bharatpedia uses, [[Help:Magic words#Variables|variables]] have a more specific meaning that distinguishes them from templates, but they are both identified by double [[Curly brackets|braces]] <code><nowiki>{{ }}</nowiki></code> and they both return a value.
In [[MediaWiki]], the [[wiki software]] that Bharatpedia uses, [[Help:Magic words#Variables|variables]] have a more specific meaning that distinguishes them from templates, but they are both identified by double [[Curly brackets|braces]] <code><nowiki>{{ }}</nowiki></code> and they both return a value.


Whereas MediaWiki variable names are all uppercase, template names have the same basic features and [[WP:NCHASHTAG|limitations]] as all [[Help:Page name|page names]]: they are case-sensitive (except for the first character); underscores are [[parsed]] as spaces; and they cannot contain any of these characters: <code><nowiki># < > [ ] | { }</nowiki></code>. This is because those are reserved for [[wiki markup]] and [[HTML]].
Whereas MediaWiki variable names are all uppercase, template names have the same basic features and [[BP:NCHASHTAG|limitations]] as all [[Help:Page name|page names]]: they are case-sensitive (except for the first character); underscores are [[parsed]] as spaces; and they cannot contain any of these characters: <code><nowiki># < > [ ] | { }</nowiki></code>. This is because those are reserved for [[wiki markup]] and [[HTML]].


The [[number sign]] <code>#</code> is called a [[fragment identifier]] because it denotes a {{em|fragment}} or section of a document (such as a [[Help:Section|section]] in a Bharatpedia article). Although it [[WP:ANCHOR|can be used]] to link to a section of a template page (like [[Template:Portal#Example]]), there is no reason to put a fragment identifier or fragment name in a template reference. In {{tnull|Portal{{var|#Location}}|Books}}, for example, the string <code>{{var|#Location}}</code> has no purpose and is thus ignored.
The [[number sign]] <code>#</code> is called a [[fragment identifier]] because it denotes a {{em|fragment}} or section of a document (such as a [[Help:Section|section]] in a Bharatpedia article). Although it [[BP:ANCHOR|can be used]] to link to a section of a template page (like [[Template:Portal#Example]]), there is no reason to put a fragment identifier or fragment name in a template reference. In {{tnull|Portal{{var|#Location}}|Books}}, for example, the string <code>{{var|#Location}}</code> has no purpose and is thus ignored.


===Substitution===
===Substitution===
{{Further|Help:Substitution}}
{{Further|Help:Substitution}}
When a template is substituted, its content is [[hard-coded]] in the page rather than [[WP:Transclusion|transcluded]]. To learn how and [[Help:Substitution#When to use substitution|when]] to substitute a template, see [[Help:Substitution]].
When a template is substituted, its content is [[hard-coded]] in the page rather than [[BP:Transclusion|transcluded]]. To learn how and [[Help:Substitution#When to use substitution|when]] to substitute a template, see [[Help:Substitution]].


==Basic template usage examples==
==Basic template usage examples==
Line 122: Line 122:
* To get a list of templates transcluded on a page, click "Edit" and find the list below the edit window. This list also includes the subtemplates used by the templates that are directly transcluded. To get such a list for a page section, an old version of the page,{{efn|For an old version, the subtemplate tree will be constructed according to the templates' current state.}} or your newly edited version prior to saving, click {{Button|Show preview}} on the appropriate edit page.
* To get a list of templates transcluded on a page, click "Edit" and find the list below the edit window. This list also includes the subtemplates used by the templates that are directly transcluded. To get such a list for a page section, an old version of the page,{{efn|For an old version, the subtemplate tree will be constructed according to the templates' current state.}} or your newly edited version prior to saving, click {{Button|Show preview}} on the appropriate edit page.
* There are limits to the number and complexity of the templates that an article may have. See the "[[#Expand limits|§ Expand limits]]" section for help in resolving this.
* There are limits to the number and complexity of the templates that an article may have. See the "[[#Expand limits|§ Expand limits]]" section for help in resolving this.
* If you want the template to leave a [[WP:~|time stamp or signature]], you can write <code>&lt;noinclude>&lt;nowiki>&lt;/noinclude><nowiki>~~~~~</nowiki>&lt;noinclude>&lt;/nowiki>&lt;/noinclude></code>, but this will only work if you substitute the template. If you transclude it, you'll just get <nowiki>~~~~~</nowiki>.
* If you want the template to leave a [[BP:~|time stamp or signature]], you can write <code>&lt;noinclude>&lt;nowiki>&lt;/noinclude><nowiki>~~~~~</nowiki>&lt;noinclude>&lt;/nowiki>&lt;/noinclude></code>, but this will only work if you substitute the template. If you transclude it, you'll just get <nowiki>~~~~~</nowiki>.
* To improve readability, usually programmers like to split the code with newlines and indent it. Unfortunately, [[MediaWiki]] software does not allow this functionality; in many instances, these purpose-built newlines are treated by the software as content. One possible workaround is to add <code>&lt;!--</code> before each newline character and <code>--></code> after it, which produces an [[HTML comment]].
* To improve readability, usually programmers like to split the code with newlines and indent it. Unfortunately, [[MediaWiki]] software does not allow this functionality; in many instances, these purpose-built newlines are treated by the software as content. One possible workaround is to add <code>&lt;!--</code> before each newline character and <code>--></code> after it, which produces an [[HTML comment]].


Line 128: Line 128:
<!--[[Help:Subtemplates]] redirects here.-->
<!--[[Help:Subtemplates]] redirects here.-->


Templates are created and edited in much the same way as any other page: choose an appropriate name, navigate to that page, then click the "Edit" tab or create a new page as needed. As mentioned above, templates are normally placed in the [[WP:Template namespace|Template namespace]], though templates intended for your own personal use or for experimentation can be created in your own [[WP:user space|user space]]. Anything that can be included on a normal page or article can be included on a template, including other templates (called ''{{dfn|subtemplates}}''). Templates often make use of programming features—parameters, parser functions, and other [[Help:Magic words|magic words]]—which allow the transcluded content to vary depending on context. There are also special tags to control which information is transcluded and which is not.
Templates are created and edited in much the same way as any other page: choose an appropriate name, navigate to that page, then click the "Edit" tab or create a new page as needed. As mentioned above, templates are normally placed in the [[BP:Template namespace|Template namespace]], though templates intended for your own personal use or for experimentation can be created in your own [[BP:user space|user space]]. Anything that can be included on a normal page or article can be included on a template, including other templates (called ''{{dfn|subtemplates}}''). Templates often make use of programming features—parameters, parser functions, and other [[Help:Magic words|magic words]]—which allow the transcluded content to vary depending on context. There are also special tags to control which information is transcluded and which is not.


Before creating a template, do a quick search for existing templates (such as by exploring [[:Category:Wikipedia templates]]) to see if there is already a template that does what you want or a similar template whose code can be copied and modified (or left in place and expanded). Look for generic templates on which the new template can be based; for example, [[WP:Navbox|navbox]] templates can be easily created by calling the generic [[Template:Navbox]].
Before creating a template, do a quick search for existing templates (such as by exploring [[:Category:Bharatpedia templates]]) to see if there is already a template that does what you want or a similar template whose code can be copied and modified (or left in place and expanded). Look for generic templates on which the new template can be based; for example, [[BP:Navbox|navbox]] templates can be easily created by calling the generic [[Template:Navbox]].


There is no hard rule about what name to choose for a template—make it short but reasonably descriptive. If similar templates exist, try to follow a consistent naming pattern. Templates can be renamed without breaking existing [[Bharatpedia:Transclusion|transclusions]] (what is called '''breakage'''), provided a [[WP:Redirect|redirect]] to the new template name is left behind.
There is no hard rule about what name to choose for a template—make it short but reasonably descriptive. If similar templates exist, try to follow a consistent naming pattern. Templates can be renamed without breaking existing [[Bharatpedia:Transclusion|transclusions]] (what is called '''breakage'''), provided a [[BP:Redirect|redirect]] to the new template name is left behind.


Be extremely careful when editing existing templates—changes made can affect a large number of pages, often in ways you might not expect. For this reason many high-use templates are [[WP:Protection|protected]] against editing except by [[WP:Administrator|administrators]] and [[WP:Template editor|template editors]]; other editors can propose changes on the talk page. Some templates offer a sandbox and [[Bharatpedia:Template test cases|test cases]] for experimentation.
Be extremely careful when editing existing templates—changes made can affect a large number of pages, often in ways you might not expect. For this reason many high-use templates are [[BP:Protection|protected]] against editing except by [[BP:Administrator|administrators]] and [[BP:Template editor|template editors]]; other editors can propose changes on the talk page. Some templates offer a sandbox and [[Bharatpedia:Template test cases|test cases]] for experimentation.


To propose the deletion or merger of unused or inappropriate templates or templates that can easily be merged, go to [[WP:Templates for discussion|Templates for discussion]] (TfD).
To propose the deletion or merger of unused or inappropriate templates or templates that can easily be merged, go to [[BP:Templates for discussion|Templates for discussion]] (TfD).


===Handling parameters===
===Handling parameters===
Line 153: Line 153:
Parameters do not get expanded when they are wrapped in {{xtag|nowiki}} tags. They aren't expanded either if placed within the actual [[XML]]-style opening tag. Thus, the following will not work within a template:
Parameters do not get expanded when they are wrapped in {{xtag|nowiki}} tags. They aren't expanded either if placed within the actual [[XML]]-style opening tag. Thus, the following will not work within a template:
*{{!mxt|<nowiki><ref name={{{param}}}> Smith, Adam (1776)...</ref></nowiki>}}
*{{!mxt|<nowiki><ref name={{{param}}}> Smith, Adam (1776)...</ref></nowiki>}}
because the parameter is not expanded. Instead, you can use the <code><nowiki>{{#tag:}}</nowiki></code> [[WP:PF|parser function]], which is—for example—used in {{tlx|sfn}} to generate the {{tag|ref}} element; see also [[Help:Magic words#Formatting|Help:Magic words § Formatting]]. Therefore, the following example will work:
because the parameter is not expanded. Instead, you can use the <code><nowiki>{{#tag:}}</nowiki></code> [[BP:PF|parser function]], which is—for example—used in {{tlx|sfn}} to generate the {{tag|ref}} element; see also [[Help:Magic words#Formatting|Help:Magic words § Formatting]]. Therefore, the following example will work:
*{{mxt|<nowiki>{{#tag:ref | Smith, Adam (1776)... | name={{{param}}} }}</nowiki>}}
*{{mxt|<nowiki>{{#tag:ref | Smith, Adam (1776)... | name={{{param}}} }}</nowiki>}}


Line 247: Line 247:


===Nesting templates===
===Nesting templates===
{{shortcut|WP:NEST}}
{{shortcut|BP:NEST}}
Templates may contain other templates—this is usually called ''{{dfn|nesting}}''. As the template is processed, the wikitext produced by any nested templates is transcluded into the nesting template, so that the final product is essentially processed from the most deeply nested template out. While fairly straightforward in application, it involves some noteworthy quirks and tricks.
Templates may contain other templates—this is usually called ''{{dfn|nesting}}''. As the template is processed, the wikitext produced by any nested templates is transcluded into the nesting template, so that the final product is essentially processed from the most deeply nested template out. While fairly straightforward in application, it involves some noteworthy quirks and tricks.


Line 259: Line 259:
:Template:A contains <code><nowiki>the quick brown {{B|{{{3}}}=fox}} jumps over...</nowiki></code> Template:A passes the word "fox" as a named parameter of Template:B whose name is A's third positional parameter.
:Template:A contains <code><nowiki>the quick brown {{B|{{{3}}}=fox}} jumps over...</nowiki></code> Template:A passes the word "fox" as a named parameter of Template:B whose name is A's third positional parameter.
:<code>{<nowiki />{#if: {{var|test string}} | {{var|value if test string is not empty}} | {<nowiki />{#if: {{var|test string}} | {{var|value if test string is not empty}} | {{var|value if test string is empty (or only white space)}} }} }}</code>
:<code>{<nowiki />{#if: {{var|test string}} | {{var|value if test string is not empty}} | {<nowiki />{#if: {{var|test string}} | {{var|value if test string is not empty}} | {{var|value if test string is empty (or only white space)}} }} }}</code>
{{shortcut|WP:TEMPLATE LOOP}}
{{shortcut|BP:TEMPLATE LOOP}}
A template can call itself but will stop after one iteration to prevent an infinite loop.
A template can call itself but will stop after one iteration to prevent an infinite loop.


Line 267: Line 267:


===<span id="Noinclude, includeonly, and onlyinclude"></span>Inclusion control: noinclude, includeonly, and onlyinclude===
===<span id="Noinclude, includeonly, and onlyinclude"></span>Inclusion control: noinclude, includeonly, and onlyinclude===
{{shortcut|WP:NOINCLUDE|WP:INCLUDEONLY|WP:ONLYINCLUDE}}
{{shortcut|BP:NOINCLUDE|BP:INCLUDEONLY|BP:ONLYINCLUDE}}
By default, when a template is [[Bharatpedia:Transclusion|transcluded]] (or [[Bharatpedia:Substitution|substituted]]), the entire wikitext (code) of the template page gets included in that of the target page. However, it is possible to modify that behaviour, using tags that specify which parts of the template code are to be included. This makes it possible to avoid transcluding information intended for display only on the template page itself, such as the template's {{tl|documentation}}, [[WP:Category|categories]], and [[WP:Interwiki links|interwiki links]]. It is also possible to have parts of the code be transcluded, but {{em|not}} be processed on the template page itself (e.g., categories to be applied to the target pages which do not apply to the template). The tags are as follows:
By default, when a template is [[Bharatpedia:Transclusion|transcluded]] (or [[Bharatpedia:Substitution|substituted]]), the entire wikitext (code) of the template page gets included in that of the target page. However, it is possible to modify that behaviour, using tags that specify which parts of the template code are to be included. This makes it possible to avoid transcluding information intended for display only on the template page itself, such as the template's {{tl|documentation}}, [[BP:Category|categories]], and [[BP:Interwiki links|interwiki links]]. It is also possible to have parts of the code be transcluded, but {{em|not}} be processed on the template page itself (e.g., categories to be applied to the target pages which do not apply to the template). The tags are as follows:
* {{xtag|noinclude|p}}&nbsp;– The text between the tags will {{em|not}} be included when the template is transcluded (substituted), but {{em|will}} be processed on the template's page; a common use is for [[Bharatpedia:Template documentation|documentation in templates]].
* {{xtag|noinclude|p}}&nbsp;– The text between the tags will {{em|not}} be included when the template is transcluded (substituted), but {{em|will}} be processed on the template's page; a common use is for [[Bharatpedia:Template documentation|documentation in templates]].
* {{xtag|onlyinclude|p}}&nbsp;– This specifies that nothing on the page {{em|except}} what appears between the tags will be transcluded (substituted).
* {{xtag|onlyinclude|p}}&nbsp;– This specifies that nothing on the page {{em|except}} what appears between the tags will be transcluded (substituted).
Line 310: Line 310:


===Problems and workarounds===
===Problems and workarounds===
* If the first character produced by a template or [[WP:PF|parser function]] is one of four wiki markup characters—<code>:</code>, <code>;</code>, <code>*</code>, <code>#</code>{{efn|These are defined in the [https://web.archive.org/web/20180625163321/https://doc.wikimedia.org/mediawiki-core/master/php/classParser.html#ad463888e40c078ac9bcfcaf1231e39d7 <code>doBlockLevels</code> function of Parser.php].}}—then it is processed as though it were at the beginning of a line, even when the template tag is not. This allows the creation of various kinds of lists in templates where the template may not always be in the correct place for a list. To avoid this, either use {{xtag|nowiki|s}} before the markup or use the [[HTML]] entities <code>&amp;#58;</code>, <code>&amp;#59;</code>, <code>&amp;#42;</code>, and <code>&amp;#35;</code> respectively. In some cases, the HTML entities will work when the {{tag|nowiki|s}} does not. The problem often occurs when a parameter value in a template call starts with one of the four characters.
* If the first character produced by a template or [[BP:PF|parser function]] is one of four wiki markup characters—<code>:</code>, <code>;</code>, <code>*</code>, <code>#</code>{{efn|These are defined in the [https://web.archive.org/web/20180625163321/https://doc.wikimedia.org/mediawiki-core/master/php/classParser.html#ad463888e40c078ac9bcfcaf1231e39d7 <code>doBlockLevels</code> function of Parser.php].}}—then it is processed as though it were at the beginning of a line, even when the template tag is not. This allows the creation of various kinds of lists in templates where the template may not always be in the correct place for a list. To avoid this, either use {{xtag|nowiki|s}} before the markup or use the [[HTML]] entities <code>&amp;#58;</code>, <code>&amp;#59;</code>, <code>&amp;#42;</code>, and <code>&amp;#35;</code> respectively. In some cases, the HTML entities will work when the {{tag|nowiki|s}} does not. The problem often occurs when a parameter value in a template call starts with one of the four characters.
* For issues involving the substitution of templates, such as how to control whether subtemplates are substituted as well when the parent template is substituted, see [[Help:Substitution]].
* For issues involving the substitution of templates, such as how to control whether subtemplates are substituted as well when the parent template is substituted, see [[Help:Substitution]].
* The template {{tlx|Strip whitespace}} can be used to strip any initial or final whitespace from unnamed parameter values if this would cause problems; named parameter values are automatically stripped in this way.
* The template {{tlx|Strip whitespace}} can be used to strip any initial or final whitespace from unnamed parameter values if this would cause problems; named parameter values are automatically stripped in this way.
Line 317: Line 317:
** Use <code>msgnw:</code> (short for "'''m'''e'''s'''sa'''g'''e, '''n'''o'''w'''iki") to more-or-less transclude the wikitext of the template page rather than the processed contents. It is not perfect: lists are rendered, comments are removed, and single newlines are replaced with spaces (which is particularly confounding when transcluding wikitext tables).
** Use <code>msgnw:</code> (short for "'''m'''e'''s'''sa'''g'''e, '''n'''o'''w'''iki") to more-or-less transclude the wikitext of the template page rather than the processed contents. It is not perfect: lists are rendered, comments are removed, and single newlines are replaced with spaces (which is particularly confounding when transcluding wikitext tables).
** Use [[Special:ExpandTemplates]] to see the full recursive expansion of one or more templates.
** Use [[Special:ExpandTemplates]] to see the full recursive expansion of one or more templates.
* To protect server resources and avoid infinite loops, the parser imposes certain limits on the depth transclusion nesting and on the page size with expanded templates. This may cause pages to break when using very complex templates, particularly if there are multiple such templates on the same page. For more information, see [[Bharatpedia:Template limits]]. A page's overall load on the server can be checked by examining the generated HTML for a page and looking for the <code>NewPP limit report</code> comments.
* To protect server resources and avoid infinite loops, the parser imposes certain limits on the depth transclusion nesting and on the page size with expanded templates. This may cause pages to break when using very complex templates, particularly if there are multiple such templates on the same page. For more information, see [[Bharatpedia:Template limits]]. A page's overall load on the server can be checked by examining the generated HTML for a page and looking for the <code>NeBPP limit report</code> comments.
* Do not use <code>=</code> wikimarkup to create section headers within a template which is intended for use in article space; this will create an <code>[edit]</code> link that, when transcluded, will confusingly open the template for editing.
* Do not use <code>=</code> wikimarkup to create section headers within a template which is intended for use in article space; this will create an <code>[edit]</code> link that, when transcluded, will confusingly open the template for editing.
** You may avoid <code>[edit]</code> links to the template by including <code><nowiki><includeonly>__NOEDITSECTION__</includeonly></nowiki></code>.
** You may avoid <code>[edit]</code> links to the template by including <code><nowiki><includeonly>__NOEDITSECTION__</includeonly></nowiki></code>.
Line 327: Line 327:
Documentation for users, together with the template's categories, is normally placed after the template code, inside {{tag|noinclude}} tags. It is normally necessary to put the opening {{tag|noinclude|o}} tag immediately after the end of the code, with no intervening spaces or newlines, to avoid transcluding unwanted whitespace.
Documentation for users, together with the template's categories, is normally placed after the template code, inside {{tag|noinclude}} tags. It is normally necessary to put the opening {{tag|noinclude|o}} tag immediately after the end of the code, with no intervening spaces or newlines, to avoid transcluding unwanted whitespace.


In the case of complex templates, the documentation (together with categories) is often kept on a separate [[WP:Subpage|subpage]] of the template page (named "Template:{{var|XXX}}/doc"). This also applies to many [[WP:Protection|protected]] templates, which allows the information to be edited by non-administrators. This is achieved by placing the {{tlx|Documentation}} template after the main template code and within {{tag|noinclude}} tags. If the "/doc" subpage does not exist, a link will then appear enabling it to be created.
In the case of complex templates, the documentation (together with categories) is often kept on a separate [[BP:Subpage|subpage]] of the template page (named "Template:{{var|XXX}}/doc"). This also applies to many [[BP:Protection|protected]] templates, which allows the information to be edited by non-administrators. This is achieved by placing the {{tlx|Documentation}} template after the main template code and within {{tag|noinclude}} tags. If the "/doc" subpage does not exist, a link will then appear enabling it to be created.


===Categorization===
===Categorization===
{{See also|Bharatpedia:Categorization#Template categorization}}
{{See also|Bharatpedia:Categorization#Template categorization}}
====Categorize pages by template inclusion====
====Categorize pages by template inclusion====
Some templates contain category definitions in their transcluded code, since they are intended to place the target pages in particular categories. This is often done with maintenance categories (placing articles into ordinary content categories in this way is discouraged). When doing this, it may be necessary to use {{tag|includeonly}} tags to keep the template itself out of the category. While developing, testing, sandboxing, or demonstrating a template intended to apply a category, either temporarily replace each category with a test category (starting with [[:Category:X1|X1]], [[:Category:X2|X2]], or [[:Category:X3|X3]]) or suppress categorization (see [[WP:CATSUP|category suppression in templates]]).
Some templates contain category definitions in their transcluded code, since they are intended to place the target pages in particular categories. This is often done with maintenance categories (placing articles into ordinary content categories in this way is discouraged). When doing this, it may be necessary to use {{tag|includeonly}} tags to keep the template itself out of the category. While developing, testing, sandboxing, or demonstrating a template intended to apply a category, either temporarily replace each category with a test category (starting with [[:Category:X1|X1]], [[:Category:X2|X2]], or [[:Category:X3|X3]]) or suppress categorization (see [[BP:CATSUP|category suppression in templates]]).
====Categorize templates====
====Categorize templates====
Categorization declaration <code><nowiki>[[Category:Some-topic templates]]</nowiki></code> should be placed on the template's documentation page (or inside {{tag|noinclude}} [[html tag|tags]] if there is no documentation page) to avoid polluting the transcluding pages.
Categorization declaration <code><nowiki>[[Category:Some-topic templates]]</nowiki></code> should be placed on the template's documentation page (or inside {{tag|noinclude}} [[html tag|tags]] if there is no documentation page) to avoid polluting the transcluding pages.
Line 338: Line 338:
===Aliases===
===Aliases===


Aliases can be created with [[WP:Redirect|redirects]]. For example, [[Template:Tsh]] redirects to [[Template:Template shortcut]]. You can then write {{tlx|tsh|{{var|foo}}}} instead of {{tlx|Template shortcut|{{var|foo}}}}.
Aliases can be created with [[BP:Redirect|redirects]]. For example, [[Template:Tsh]] redirects to [[Template:Template shortcut]]. You can then write {{tlx|tsh|{{var|foo}}}} instead of {{tlx|Template shortcut|{{var|foo}}}}.


It is good to prepare template aliases which only differ in whitespaces and capitalization. For example, there is a template called {{tlx|See Wiktionary}}. The "W" is capital, since the word "Wiktionary" is so, but a redirect {{tlx|See wiktionary}} with lower "w" exists because users may type the latter instead.
It is good to prepare template aliases which only differ in whitespaces and capitalization. For example, there is a template called {{tlx|See Wiktionary}}. The "W" is capital, since the word "Wiktionary" is so, but a redirect {{tlx|See wiktionary}} with lower "w" exists because users may type the latter instead.
Line 346: Line 346:
{{Anchor|Expand limits}}
{{Anchor|Expand limits}}
{{details|Bharatpedia:Template limits}}
{{details|Bharatpedia:Template limits}}
'''"Post-expand include size" limit.''' When templates are rendered or expanded to HTML for viewing in your browser, they use memory. This is called the "post-expand include size" and has a limit of 2,048,000&nbsp;bytes. This size is included as an invisible comment in the HTML output—use your browser's view source feature to show the raw HTML and search for "newpp". The report will look like:
'''"Post-expand include size" limit.''' When templates are rendered or expanded to HTML for viewing in your browser, they use memory. This is called the "post-expand include size" and has a limit of 2,048,000&nbsp;bytes. This size is included as an invisible comment in the HTML output—use your browser's view source feature to show the raw HTML and search for "neBPp". The report will look like:
<syntaxhighlight lang="html4strict">
<syntaxhighlight lang="html4strict">
<!--
<!--
NewPP limit report
NeBPP limit report
Preprocessor node count: 2382/1000000
Preprocessor node count: 2382/1000000
Post-expand include size: 63476/2048000 bytes
Post-expand include size: 63476/2048000 bytes
Line 440: Line 440:
{{Notelist}}
{{Notelist}}


{{Wikipedia template messages|state=collapsed}}
{{Bharatpedia template messages|state=collapsed}}
{{Wikipedia technical help|collapsed}}
{{Bharatpedia technical help|collapsed}}
[[Category:Wikipedia how-to]]
[[Category:Bharatpedia how-to]]
[[Category:Wikipedia template help]]
[[Category:Bharatpedia template help]]
Bots, trusted
7,437

edits