Bots, trusted
7,437
edits
CleanupBot (talk | contribs) m (Remove protection template from unprotected page) |
WikiDwarfBOT (talk | contribs) m (clean up, replaced: Wikipedia: → Bharatpedia: (27)) |
||
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| | {{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}} | {{Wikipedia how to|H:T|WP: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 [[ | 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. | ||
The most common method of inclusion is called [[ | 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. | ||
[[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 132: | Line 132: | ||
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: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]]. | ||
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 [[ | 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. | ||
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 [[ | 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. | ||
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 [[WP:Templates for discussion|Templates for discussion]] (TfD). | ||
Line 268: | Line 268: | ||
===<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|WP:NOINCLUDE|WP:INCLUDEONLY|WP:ONLYINCLUDE}} | ||
By default, when a template is [[ | 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: | ||
* {{xtag|noinclude|p}} – 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 [[ | * {{xtag|noinclude|p}} – 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}} – This specifies that nothing on the page {{em|except}} what appears between the tags will be transcluded (substituted). | * {{xtag|onlyinclude|p}} – This specifies that nothing on the page {{em|except}} what appears between the tags will be transcluded (substituted). | ||
* {{xtag|includeonly|p}} – The text between the tags {{em|will}} be transcluded (substituted), but will {{em|not}} be processed on the template's own page. | * {{xtag|includeonly|p}} – The text between the tags {{em|will}} be transcluded (substituted), but will {{em|not}} be processed on the template's own page. | ||
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 [[ | * 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. | ||
* 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>. | ||
===Documentation=== | ===Documentation=== | ||
{{Details| | {{Details|Bharatpedia:Template documentation}} | ||
Categorizing your template and documenting its proper usage will make it easier for other editors to find and use. | Categorizing your template and documenting its proper usage will make it easier for other editors to find and use. | ||
Line 330: | Line 330: | ||
===Categorization=== | ===Categorization=== | ||
{{See also| | {{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 [[WP:CATSUP|category suppression in templates]]). | ||
Line 345: | Line 345: | ||
{{Anchor|Expand limits}} | {{Anchor|Expand limits}} | ||
{{details| | {{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 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 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: | ||
<syntaxhighlight lang="html4strict"> | <syntaxhighlight lang="html4strict"> | ||
Line 359: | Line 359: | ||
The example shows that template expansion is using 63,476 bytes out of 2,048,000 bytes of available memory. | The example shows that template expansion is using 63,476 bytes out of 2,048,000 bytes of available memory. | ||
'''Display problem.''' If too many templates are included on a page, the post-expand include size may exceed the limit. When this happens, templates after the limit will no longer expand and will instead display as a wikilink (for example, {{red|1=<u>Template:{{var|Template name}}</u>}}). Common causes are the inclusion of too many citation templates and/or flag templates. To resolve this problem [[ | '''Display problem.''' If too many templates are included on a page, the post-expand include size may exceed the limit. When this happens, templates after the limit will no longer expand and will instead display as a wikilink (for example, {{red|1=<u>Template:{{var|Template name}}</u>}}). Common causes are the inclusion of too many citation templates and/or flag templates. To resolve this problem [[Bharatpedia:Substitution|substitute]] templates, remove templates, or [[Bharatpedia:Splitting|split]] the page. | ||
'''Non-rendered tranclusions still count towards limit.''' For example, a page which contains only <code><nowiki>{{#if:{{:Main Page}}}}</nowiki></code> would still have a post-expand include size even though it would have no output at all. | '''Non-rendered tranclusions still count towards limit.''' For example, a page which contains only <code><nowiki>{{#if:{{:Main Page}}}}</nowiki></code> would still have a post-expand include size even though it would have no output at all. | ||
The same applies to [[ | The same applies to [[Bharatpedia:Lua|Scribunto modules]]. For example, <code><nowiki>{{#invoke:Test|main}}</nowiki></code> would still increase post-expand include size even if Module:Test were simply: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
mw.getCurrentFrame():preprocess "{{msgnw::Main Page}}" -- remove this line and post-expand include size becomes zero | mw.getCurrentFrame():preprocess "{{msgnw::Main Page}}" -- remove this line and post-expand include size becomes zero | ||
Line 371: | Line 371: | ||
==Lua programming language== | ==Lua programming language== | ||
{{main article| | {{main article|Bharatpedia:Lua}} | ||
Since February 2013, the [[Lua (programming language)|Lua programming language]] is available for use through the [[mw:Extension:Scribunto|Scribunto]] MediaWiki extension. Lua code can be embedded into templates by employing the <code><nowiki>{{#invoke:}}</nowiki></code> functionality of the Scribunto MediaWiki extension. The Lua [[source code]] is stored in pages called modules, and these individual modules are then invoked on template pages. For example, [[Module:Example]] can be invoked using the code <code><nowiki>{{#invoke:Example|hello}}</nowiki></code> to print the text "{{#invoke:Example|hello}}". | Since February 2013, the [[Lua (programming language)|Lua programming language]] is available for use through the [[mw:Extension:Scribunto|Scribunto]] MediaWiki extension. Lua code can be embedded into templates by employing the <code><nowiki>{{#invoke:}}</nowiki></code> functionality of the Scribunto MediaWiki extension. The Lua [[source code]] is stored in pages called modules, and these individual modules are then invoked on template pages. For example, [[Module:Example]] can be invoked using the code <code><nowiki>{{#invoke:Example|hello}}</nowiki></code> to print the text "{{#invoke:Example|hello}}". | ||
==Template search== | ==Template search== | ||
{{main| | {{main|Bharatpedia:Template messages}} | ||
As an alternative to using this index linked above, you can search the Template namespace using the [[Special:Search]] box below: | As an alternative to using this index linked above, you can search the Template namespace using the [[Special:Search]] box below: | ||
<div class="inputbox-hidecheckboxes"> | <div class="inputbox-hidecheckboxes"> | ||
Line 397: | Line 397: | ||
|- style="vertical-align:top;" | |- style="vertical-align:top;" | ||
| | | | ||
*[[ | *[[Bharatpedia:Advanced template coding]] | ||
* [[m:Help:Template]] | * [[m:Help:Template]] | ||
* [[meta:User:Happy-melon/Templates]] | * [[meta:User:Happy-melon/Templates]] | ||
Line 407: | Line 407: | ||
* [[Help:Metatemplating]] | * [[Help:Metatemplating]] | ||
* [[Help:Calculation]] | * [[Help:Calculation]] | ||
* [[ | * [[Bharatpedia:Template messages]] | ||
* [[Help:Magic words]] | * [[Help:Magic words]] | ||
* [[mw:Help:Magic words]] | * [[mw:Help:Magic words]] | ||
Line 413: | Line 413: | ||
* [[m:Help:Parameter default]]<!-- m: --> | * [[m:Help:Parameter default]]<!-- m: --> | ||
* [[Help:Substitution]]<!-- maybe portable, test it --> | * [[Help:Substitution]]<!-- maybe portable, test it --> | ||
* [[ | * [[Bharatpedia:Template documentation]] | ||
* [[ | * [[Bharatpedia:Template namespace]] | ||
* [[ | * [[Bharatpedia:Template limits]] | ||
* [[ | * [[Bharatpedia:Template sandbox and test cases]] | ||
* [[ | * [[Bharatpedia:WikiProject Templates]] | ||
*[[ | *[[Bharatpedia:TemplateData]], the standardized description of a template, used by VisualEditor | ||
| | | | ||
* [[mw:Manual:$wgEnableScaryTranscluding|Interwiki transclusion]] | * [[mw:Manual:$wgEnableScaryTranscluding|Interwiki transclusion]] | ||
Line 424: | Line 424: | ||
* [[mw:Manual:Parser.php]] | * [[mw:Manual:Parser.php]] | ||
| | | | ||
* [[ | * [[Bharatpedia:Database reports/Templates transcluded on the most pages]]—shows the number of pages in which each template is transcluded, not counting transclusions through redirects | ||
* [[Special:Unusedtemplates]]—templates which are not transcluded (however, they may be used for substitution) | * [[Special:Unusedtemplates]]—templates which are not transcluded (however, they may be used for substitution) | ||
* [{{fullurl:Special:Allpages|namespace=10}} Special:Allpages (namespace 10)] all templates on this server | * [{{fullurl:Special:Allpages|namespace=10}} Special:Allpages (namespace 10)] all templates on this server | ||
Line 432: | Line 432: | ||
* CSS and JS pages, see [[Help:User style]] | * CSS and JS pages, see [[Help:User style]] | ||
* Pages in the MediaWiki namespace, see [[Help:System message]] | * Pages in the MediaWiki namespace, see [[Help:System message]] | ||
* [[ | * [[Bharatpedia:Book sources]], used by [[Special:Booksources]] | ||
* [[m:Spam blacklist]] | * [[m:Spam blacklist]] | ||
* [[Template:Example]] | * [[Template:Example]] |