Help:Template: Difference between revisions

Content deleted Content added
Help pages: update links - most o the Meta pages were moved to MediaWikiWiki earlier this year by Pppery
Line 26:
==Using templates==
===General===
Using a template is muchsimilar liketo calling a [[SubroutineFunction (computer programming)|function]] in a programming. languageWhen called call(known as a ''template itcall''), and it returns a value. For a templateresult, theknown return value is calledas the ''expansion'' of the template, andwhich is treated asbecomes part of the calling page's source. Like functions, some templates acceptcan take parameters that affectmodify thetheir output.
 
CallingWhen a template causesis called, it tocan be either ''transcluded'' or ''substituted'' in the page that calls it (which is known as the ''target page'').
 
Transcluding a template[[Wikipedia:Transclusion|Transclusion]] means that when MediaWiki displays the page, it treats the template as if it were directly in the wikipage’s source. ofThis the page, whereas substituting means MediaWikimethod doesensures that when it <em>saves</em> the page (i.e. the contentupdates ofto the template getsautomatically storedreflect asin part of the targetevery page andwhere subsequentit’s editors cannot tell that it got there via a template)used.
 
[[Substitutionary atonement|Substitution]] differs in that it inserts the content of the template permanently into the target page when it is <em>saves</em>. This means subsequent editors cannot tell that it originated from a template.
To transclude a template into a page, put {{tnull|{{var|Template&nbsp;name}}}} in the page source at the place where the template is to appear. The first letter of each word of the title may equivalently be lower- or upper-case.
 
To substitutetransclude a template, intoinsert a{{tnull|{{var|Template&nbsp;name}}}} at the point where it should appear in the page source. To substitute it, use {{tnull|subst:{{var|Template&nbsp;name}}}} instead.
 
WhereasIn [[MediaWiki]], variablethe names[[wiki software]] that Wikipedia uses, [[Help:Magic words#Variables|variables]] are alldistinct from templates, but both are identified by double [[Curly brackets|curly braces]] <code>{{ }}</code>, but they differ: variables in MediaWiki are always uppercase, while template names havefollow the same basic featuresconventions and have the same [[WP:NCHASHTAG|limitations]] as all [[Help:Page namenames|page names]]:, they areincluding [[Case sensitivity|case-sensitivesensitivity]] (except for the first character); [[underscore]]s are parsed as spaces; and theytemplate names cannot contain anycertain ofcharacters: theseand limited characters: <code><nowiki># < > [ ] | { }</nowiki></code>. This is because those are reserved for [[wiki markup]].
This wikitext is called a ''template call''.
 
The [[number sign]] <code>#</code> denotesis used as a [[URI fragment|fragment identifier]], which identifies a {{em|fragment}} or section of a document (such as a [[Help:Section|section]] inof a page or Wikipedia article). Although you can use it in a [[WP:LINK|link]] to link to a section of a template page (likee.g., [[Template:Portal#Example]]), fragment identifiers have no meaning in a template call and are ignored. For example, {{tnull|Portal{{var|#Location}}|Books}} is the same as {{tnull|Portal|Books}}.
In [[MediaWiki]], the [[wiki software]] that Wikipedia uses, [[Help:Magic words#Variables|variables]] are distinct from templates, but they are both identified by double [[Curly brackets|braces]] <code><nowiki>{{ }}</nowiki></code> and they both return a value.
 
The template namespace is the default, so you can leave out the namespace <code>Template:</code> in the template name, and it is conventional to do so. However, you must specify the namespace prefix for templates in other namespaces, such as <code>User:</code>. To transclude a page in [[WP:MAINSPACE|mainspace]], precede its titlepage name with a colon, as <code>{<nowiki />{:{{var|Page name}}}}</code>.
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 sensitivity|case-sensitive]] (except for the first character); [[underscore]]s 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]].
 
{{A note}} Attempting to transclude a template that does not exist produces a [[WP:Red link|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 pagestemplates between projects (such as different-language Wikipedias or MediaWiki)—to – to use a template on another language project, a copy of the template must be created in that project.
The [[number sign]] <code>#</code> denotes a [[URI fragment|fragment identifier]], which identifies a {{em|fragment}} or section of a document (such as a [[Help:Section|section]] in a Wikipedia article). Although you can use it in a [[WP:LINK|link]] to link to a section of a template page (like [[Template:Portal#Example]]), fragment identifiers have no meaning in a template call and are ignored. For example, {{tnull|Portal{{var|#Location}}|Books}} is the same as {{tnull|Portal|Books}}.
 
The template namespace is the default, so you can leave out the namespace <code>Template:</code> in the template name, and it is conventional to do so. However, you must specify the namespace prefix for templates in other namespaces, such as <code>User:</code>. To transclude a page in [[WP:MAINSPACE|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:Red link|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.
 
===Parameters===