Help:Template: Difference between revisions

14 bytes added ,  17 April 2021
m
Fixing name
m (1 revision imported)
m (Fixing name)
Line 4: Line 4:
{{Wikipedia how to|H:T|WP:TEMPLATE}}
{{Wikipedia how to|H:T|WP:TEMPLATE}}
{{Wiki markup}}
{{Wiki markup}}
A '''template''' is a Wikipedia 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 [[Wikipedia: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 [[Wikipedia: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 [[Wikipedia: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 [[Wikipedia: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.
Line 11: Line 11:


== Template link to template==
== Template link to template==
To include the actual full name of the template as text (including the surrounding braces) in a Wikipedia article, apply the [[template:template link|'''template link''' template]].  The primary motivation to do this is in instruction and documentation. A short example is the code:
To include the actual full name of the template as text (including the surrounding braces) in a Bharatpedia article, apply the [[template:template link|'''template link''' template]].  The primary motivation to do this is in instruction and documentation. A short example is the code:


::<code><nowiki>{{tl|foo}}</nowiki></code>
::<code><nowiki>{{tl|foo}}</nowiki></code>
Line 28: Line 28:
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 [[WP: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 Wikipedias 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 [[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.


==Usage syntax==
==Usage syntax==
Line 54: Line 54:
Using a template is much like calling a [[Function (computer science)|function]] in a programming language – call it and it returns a value (the [[Input/output|output]]). Like functions, some templates accept parameters that change the output.
Using a template is much like calling a [[Function (computer science)|function]] in a programming language – call it and it returns a value (the [[Input/output|output]]). Like functions, some templates accept parameters that change the output.


In [[MediaWiki]], the [[wiki software]] that Wikipedia 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 [[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]].


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 Wikipedia 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 [[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.


===Substitution===
===Substitution===
Line 158: Line 158:


====Caution: overextending URLs====
====Caution: overextending URLs====
If a parameter's value is (or ends with) a [[URL]], check whether it is displayed in Wikipedia with the link overextending by one or more characters after the URL so that clicking the link causes an error or failure. Ensure that, after processing by the software, a soft space ({{em|not}} a [[Non-breaking space|hard or non-breaking space]]) follows the URL, regardless of whether you or a user supplied the URL or whether it was generated by automated processing. Possibly, the source code could contain or generate a space that is discarded in the processing or there might not be any space there. Correct the source code, perhaps by forcing a soft space to appear after the URL. The {{tlx|spaces}} template may be useful.
If a parameter's value is (or ends with) a [[URL]], check whether it is displayed in Bharatpedia with the link overextending by one or more characters after the URL so that clicking the link causes an error or failure. Ensure that, after processing by the software, a soft space ({{em|not}} a [[Non-breaking space|hard or non-breaking space]]) follows the URL, regardless of whether you or a user supplied the URL or whether it was generated by automated processing. Possibly, the source code could contain or generate a space that is discarded in the processing or there might not be any space there. Correct the source code, perhaps by forcing a soft space to appear after the URL. The {{tlx|spaces}} template may be useful.


===System variables and conditional logic===
===System variables and conditional logic===
Line 182: Line 182:
| {{NS: 1 }}
| {{NS: 1 }}
|-
|-
| Getting a Wikipedia URL
| Getting a Bharatpedia URL
| <syntaxhighlight lang="smarty" inline>{{fullurl: pagename }}</syntaxhighlight>
| <syntaxhighlight lang="smarty" inline>{{fullurl: pagename }}</syntaxhighlight>
| {{fullurl: pagename }}
| {{fullurl: pagename }}
16,952

edits