FANDOM


(Fix a link.)
(alright a few updates to this. update based on editor, also making the page look better)
Line 1: Line 1:
 
<!-- {{Uni-vid|FANDOM_University_-_How_Templates_Work}} -->
 
<!-- {{Uni-vid|FANDOM_University_-_How_Templates_Work}} -->
 
{{tocright}}
 
{{tocright}}
{{Needs editor update}}
+
A '''template''' is a special type of page that is made so its content can be included in other pages. Since a given template can be included in many pages, it can help reduce duplication and promote a uniform style between pages.
A '''template''' is a special type of page that has been designed so its content can be included in other pages. Since a given template can be included in many pages, it can help reduce duplication and promote a uniform style between pages.
 
   
Templates can be useful for...
+
== Overview ==
  +
Templates are useful for:
 
* Creating content that should appear on many pages.
 
* Creating content that should appear on many pages.
* Formatting content (such as [[Help:Infoboxes|infoboxes]]) in a way that should be consistent across many pages.
+
* Formatting content or data (such as [[Help:Infoboxes|infoboxes]]) in a way that should be consistent across many pages.
 
* Creating a shortcut to a frequently-visited page or for writing things that you repeat often when communicating with others.
 
* Creating a shortcut to a frequently-visited page or for writing things that you repeat often when communicating with others.
 
* Replacing long, complicated code so that a page is easier for other users to edit.
 
* Replacing long, complicated code so that a page is easier for other users to edit.
 
* [[Help:Page protection|Protecting]] parts of a page from editing while leaving other sections open for edits.
 
* [[Help:Page protection|Protecting]] parts of a page from editing while leaving other sections open for edits.
   
Templates are usually located in the [{{fullurl:{{ns:-1}}:AllPages|namespace=10}} {{ns:Template}} namespace]. This includes any page with a name beginning with <code>Template:</code>, such as <code>Template:''Name''</code>. A list of '''''used''''' templates can be seen in [[Special:Templates]] and can be filtered by [[Help:Template types|template types]].
+
Templates are located in the [{{fullurl:{{ns:-1}}:AllPages|namespace=10}} {{ns:Template}} namespace]. This includes any page with a name beginning with <code>Template:</code>, such as <code>Template:''Name''</code>. A list of '''''used''''' templates can be seen in [[Special:Templates]] and can be filtered by [[Help:Template types|template types]].
   
'''Note:''' Templates cannot be edited by anonymous users<ref>[[w:User_blog:Rappy_4187/Technical_Update:_November_30,_2015|Technical Update: November 30, 2015]]</ref>.
+
Templates are most easily edited in [[Help:Source edit mode|source edit mode]].
  +
  +
Templates cannot be edited by anonymous users as of [[w:User_blog:Rappy_4187/Technical_Update:_November_30,_2015|Technical Update: November 30, 2015]].
  +
  +
== Adding pre-existing templates ==
  +
[[File:Insert template in VisualEditor.png|thumb|Selecting a template in VisualEditor]]
  +
New Fandom communities come with pre-loaded default templates. You can view a complete list of templates available on your community by going to [[Special:AllPages]] and selecting "Template" from the namespace dropdown menu. Click "Go" and all available templates will appear in a list.
  +
  +
* In the default [[Help:VisualEditor|VisualEditor]], click on the top-left "Insert" and then click "Templates" from the dropdown list, or begin by typing <code><nowiki>{{</nowiki></code>, to bring up a list of templates, and then search for the name of the template you want.
  +
* In source edit mode, you can use the code <code><nowiki>{{Template name}}</nowiki></code> to add any template to your page.
  +
* In the [[Help:Classic editor|classic editor]], you can also select from the list of all templates available on your community by clicking "Add other templates".
  +
* Advanced users can edit the page ''MediaWiki:Editor-template-list'' to directly show up to four common templates in this section. The wikitext should be written like this, one per line:
  +
*: <code><nowiki>* Template:Templatename</nowiki></code>
  +
  +
Additionally, many templates can be found on the semi-official [[w:c:templates|Templates Wiki]] (for basic templates) and the [[w:c:dev|Fandom Developers Wiki]] (for more advanced templates), and can be used on your wiki or contributed to. See [[#Copying and updating templates|below]] for more.
   
 
== How to create a basic template ==
 
== How to create a basic template ==
Line 21: Line 21:
 
* Click "Publish". You have just created a template with some sample content.
 
* Click "Publish". You have just created a template with some sample content.
 
* On your community, create a new article called "Template test".
 
* On your community, create a new article called "Template test".
* In the editor, go to source mode and enter the following code:
+
* The next step to add the template to a page varies based on your chosen editor:
:<code><nowiki>{{Example}}</nowiki></code>
+
** In the default VisualEditor mode, click the "Insert" dropdown on the top-left and select "Template", then search for "Example" in the search bar, and select it. Click "X" on the screen that appears to add the template to the page.
* Going into visual mode and entering the following code also works:
+
** In the source edit mode, enter the following code: <code><nowiki>{{Example}}</nowiki></code>
:<code><nowiki>{{Template:Example}}</nowiki></code>
+
** In classic editor's visual mode, entering the following code also works: <code><nowiki>{{Template:Example}}</nowiki></code>
 
* Click "Publish". Your "Testing Templates" page should display the text you added to your template.
 
* Click "Publish". Your "Testing Templates" page should display the text you added to your template.
* Once the template has been published, you can hover over it in visual mode where the template name will be displayed
 
   
 
You've successfully created and used a template! Now you can change the content of your template and add it to more pages to make it more useful for your community.
 
You've successfully created and used a template! Now you can change the content of your template and add it to more pages to make it more useful for your community.
 
== Adding pre-existing templates ==
 
[[File:Templates-rightrail.png|300px|right]]
 
New Fandom communities come with pre-loaded default templates. You can view a complete list of templates available on your community by going to [[Special:AllPages]] and selecting "Template" from the namespace dropdown menu. Click "Go" and all available templates will appear in a list.
 
* In the editor's visual mode, you can select from the list of all templates available on your community by clicking "Add other templates".
 
* In source mode, you can use the code <code><nowiki>{{Template name}}</nowiki></code> to add any template to your page.
 
* Advanced users can edit the page ''MediaWiki:Editor-template-list'' to directly show up to four common templates in this section. The wikitext should be written like this, one per line:
 
*: <code><nowiki>* Template:Templatename</nowiki></code>
 
   
 
== Advanced templates ==
 
== Advanced templates ==
 
=== Template parameters ===
 
=== Template parameters ===
  +
[[File:Rachel_VE_template.png|thumb|250px|Selecting parameters in VisualEditor's template tool]]
 
Templates can have '''parameters'''. These allow you to alter the way the template is displayed, such as including specific text or altering the design.
 
Templates can have '''parameters'''. These allow you to alter the way the template is displayed, such as including specific text or altering the design.
   
 
To take [[Template:Wikipedia]] as an example, adding just <code><nowiki>{{Wikipedia}}</nowiki></code> assumes that the page on Wikipedia is the same name as the page of the current page the template is used on. However, a parameter can be added, e.g. <code><nowiki>{{Wikipedia|Microsoft}}</nowiki></code>, to tell the template that the page on Wikipedia was [[wikipedia:Microsoft|Microsoft]].
 
To take [[Template:Wikipedia]] as an example, adding just <code><nowiki>{{Wikipedia}}</nowiki></code> assumes that the page on Wikipedia is the same name as the page of the current page the template is used on. However, a parameter can be added, e.g. <code><nowiki>{{Wikipedia|Microsoft}}</nowiki></code>, to tell the template that the page on Wikipedia was [[wikipedia:Microsoft|Microsoft]].
   
To learn more about how to change the output of the template based on what the user inputs, see [[Help:Template parameters]] and [[Help:Parser functions]].
+
In source mode editor, the code <code><nowiki>{{Wikipedia|Microsoft}}</nowiki></code> will use the parameter. In VisualEditor, the parameters are simply changed by clicking on the template.
  +
  +
It is possible to change the output of a template based on what the user inputs when editing the template in source editor. To learn more about how todo this, see [[Help:Template parameters]] and [[Help:Parser functions]].
   
 
=== Substituting templates ===
 
=== Substituting templates ===
A different way to use a template is to ''substitute'' its content into a page. This is done by inserting <code>subst:</code> immediately after the opening braces: <code><nowiki>{{</nowiki>subst:''templatename''}}</code>. Once the page is saved, the link to the template is removed and the template output is substituted in its place and can be further edited. Any updates to the template will not affect the content that was substituted into the page.
+
A different way to use a template is to ''substitute'' its content into a page. This can only be done in source editor, and is done by inserting <code>subst:</code> immediately after the opening braces: <code><nowiki>{{</nowiki>subst:''templatename''}}</code>. Once the page is saved, the link to the template is removed and the template output is substituted in its place and can be further edited. Any updates to the template will not affect the content that was substituted into the page.
   
 
To learn more, visit [[Help:Substituting templates]].
 
To learn more, visit [[Help:Substituting templates]].
Line 53: Line 45:
 
== Copying and updating templates ==
 
== Copying and updating templates ==
 
=== Updating and adding standard templates ===
 
=== Updating and adding standard templates ===
The official [[w:c:starter|Starter Wiki]] and semi-official [[w:c:templates|Templates Wiki]] occasionally improve some of their documentation as well as adding new templates specifically designed for Fandom sites, and are therefore worth checking from time to time.
+
The official [[w:c:starter|Starter Wiki]], [[w:c:dev|Fandom Developers Wiki]], and semi-official [[w:c:templates|Templates Wiki]] occasionally improve some of their documentation as well as adding new templates specifically designed for Fandom sites, and are therefore worth checking from time to time.
   
 
=== Copying templates from other wikis ===
 
=== Copying templates from other wikis ===
Contributors throughout Fandom have made all different kinds of templates. It is often simpler to copy an existing template and modify it for your needs, rather than creating one from scratch. The [[w:c:templates|Templates Wiki]] is a good place to start looking for a template that fits your needs. In most cases, you are free to copy templates based on the shared [[Help:Copyright#Your Copyright on Fandom|CC-BY-SA license]], but make sure the community you want to copy from does not have an alternative licensing scheme that may place restrictions on what you can copy. Giving credit to the community which you copied the template from is recommended and would likely be appreciated by that community.
+
Contributors throughout Fandom have made all different kinds of templates. It is often simpler to copy an existing template and modify it for your needs, rather than creating one from scratch. The [[w:c:templates|Templates Wiki]] is a good place to start looking for a template that fits your needs, though an established wiki for a closely related subject to that of your wiki may already have the template you need.
  +
  +
In most cases, you are free to copy templates based on the shared [[Help:Copyright#Your Copyright on Fandom|CC-BY-SA license]], but make sure the community you want to copy from does not have an alternative licensing scheme that may place restrictions on what you can copy. Giving credit to the community which you copied the template from is recommended and would likely be appreciated by that community.
   
 
Here are some basic steps to copy most templates:
 
Here are some basic steps to copy most templates:
 
# Find the template you want to copy (usually <tt>https://</tt>''wikiname''<tt>.fandom.com/wiki/Template:</tt>''templatename'').
 
# Find the template you want to copy (usually <tt>https://</tt>''wikiname''<tt>.fandom.com/wiki/Template:</tt>''templatename'').
# Click the Edit button, select all of the [[Help:Wikitext|wikitext]] and copy it.
+
# Click the Edit button, select all of the [[Help:Wikitext|wikitext]], and copy it.
 
# Create a new template page on your community (<tt>https://</tt>''yourwiki''<tt>.fandom.com/wiki/Template:</tt>''templatename''<tt>?action=edit</tt>).
 
# Create a new template page on your community (<tt>https://</tt>''yourwiki''<tt>.fandom.com/wiki/Template:</tt>''templatename''<tt>?action=edit</tt>).
 
# Paste the wikitext code you copied and press the '''Publish''' button.
 
# Paste the wikitext code you copied and press the '''Publish''' button.
Many templates have a separate subpage for documentation about the template. Fortunately, the location is often standardized, so it is easy to copy the documentation as well. If you notice the template page you copied above does not look like the original, it is likely the documentation is on a separate subpage:
+
Many templates have a separate subpage for documentation about the template, normally in <code><nowiki><nowiki></nowiki></code> tags. Fortunately, the location is often standardized, so it is easy to copy the documentation as well. If you notice the template page you copied above does not look like the original, it is likely the documentation is on a separate subpage:
 
# Find the template documentation you want to copy (usually <tt>https://</tt>''wikiname''<tt>.fandom.com/wiki/Template:</tt>''templatename''<tt>/doc</tt>).
 
# Find the template documentation you want to copy (usually <tt>https://</tt>''wikiname''<tt>.fandom.com/wiki/Template:</tt>''templatename''<tt>/doc</tt>).
 
# Click the "Edit" button, select all the wikitext and copy it.
 
# Click the "Edit" button, select all the wikitext and copy it.
Line 70: Line 62:
   
 
===Previewing edited template===
 
===Previewing edited template===
It is desirable to preview any template you have edited. Normally you can then click "Publish" from the preview screen. However, if nothing then seems to happen, the template probably has no data type yet, so click "Back" and check.
+
If using the source or classic edit modes, it is desirable to preview any template you have edited. Normally you can then click "Publish" from the preview screen. VisualEditor will show the template by default.
   
 
== See also ==
 
== See also ==
Line 83: Line 75:
 
== Further help and feedback ==
 
== Further help and feedback ==
 
{{Help and feedback section}}
 
{{Help and feedback section}}
+
[[de:Hilfe:Vorlagen]]
== References ==
 
<references />[[de:Hilfe:Vorlagen]]
 
 
[[es:Ayuda:Plantillas]]
 
[[es:Ayuda:Plantillas]]
 
[[fi:Ohje:Mallineet]]
 
[[fi:Ohje:Mallineet]]

Revision as of 20:30, June 26, 2019

A template is a special type of page that is made so its content can be included in other pages. Since a given template can be included in many pages, it can help reduce duplication and promote a uniform style between pages.

Overview

Templates are useful for:

  • Creating content that should appear on many pages.
  • Formatting content or data (such as infoboxes) in a way that should be consistent across many pages.
  • Creating a shortcut to a frequently-visited page or for writing things that you repeat often when communicating with others.
  • Replacing long, complicated code so that a page is easier for other users to edit.
  • Protecting parts of a page from editing while leaving other sections open for edits.

Templates are located in the Template namespace. This includes any page with a name beginning with Template:, such as Template:Name. A list of used templates can be seen in Special:Templates and can be filtered by template types.

Templates are most easily edited in source edit mode.

Templates cannot be edited by anonymous users as of Technical Update: November 30, 2015.

Adding pre-existing templates

Insert template in VisualEditor

Selecting a template in VisualEditor

New Fandom communities come with pre-loaded default templates. You can view a complete list of templates available on your community by going to Special:AllPages and selecting "Template" from the namespace dropdown menu. Click "Go" and all available templates will appear in a list.

  • In the default VisualEditor, click on the top-left "Insert" and then click "Templates" from the dropdown list, or begin by typing {{, to bring up a list of templates, and then search for the name of the template you want.
  • In source edit mode, you can use the code {{Template name}} to add any template to your page.
  • In the classic editor, you can also select from the list of all templates available on your community by clicking "Add other templates".
  • Advanced users can edit the page MediaWiki:Editor-template-list to directly show up to four common templates in this section. The wikitext should be written like this, one per line:
    * Template:Templatename

Additionally, many templates can be found on the semi-official Templates Wiki (for basic templates) and the Fandom Developers Wiki (for more advanced templates), and can be used on your wiki or contributed to. See below for more.

How to create a basic template

Templates can be very powerful, but also sometimes very complicated. It often helps to start by creating the simplest possible kind of template, and then experimenting from there.

  • On your community, navigate to "Template:Example" using the address bar of your browser and click "Create" which can be found in the top right corner of the content section.
  • You should see a popup asking you to Choose template type; check one of the options. If none match to what you're are looking for, check "Unknown".
  • Type a couple of words or a sentence in the editor.
  • Click "Publish". You have just created a template with some sample content.
  • On your community, create a new article called "Template test".
  • The next step to add the template to a page varies based on your chosen editor:
    • In the default VisualEditor mode, click the "Insert" dropdown on the top-left and select "Template", then search for "Example" in the search bar, and select it. Click "X" on the screen that appears to add the template to the page.
    • In the source edit mode, enter the following code: {{Example}}
    • In classic editor's visual mode, entering the following code also works: {{Template:Example}}
  • Click "Publish". Your "Testing Templates" page should display the text you added to your template.

You've successfully created and used a template! Now you can change the content of your template and add it to more pages to make it more useful for your community.

Advanced templates

Template parameters

Rachel VE template

Selecting parameters in VisualEditor's template tool

Templates can have parameters. These allow you to alter the way the template is displayed, such as including specific text or altering the design.

To take Template:Wikipedia as an example, adding just {{Wikipedia}} assumes that the page on Wikipedia is the same name as the page of the current page the template is used on. However, a parameter can be added, e.g. {{Wikipedia|Microsoft}}, to tell the template that the page on Wikipedia was Microsoft.

In source mode editor, the code {{Wikipedia|Microsoft}} will use the parameter. In VisualEditor, the parameters are simply changed by clicking on the template.

It is possible to change the output of a template based on what the user inputs when editing the template in source editor. To learn more about how todo this, see Help:Template parameters and Help:Parser functions.

Substituting templates

A different way to use a template is to substitute its content into a page. This can only be done in source editor, and is done by inserting subst: immediately after the opening braces: {{subst:templatename}}. Once the page is saved, the link to the template is removed and the template output is substituted in its place and can be further edited. Any updates to the template will not affect the content that was substituted into the page.

To learn more, visit Help:Substituting templates.

Copying and updating templates

Updating and adding standard templates

The official Starter Wiki, Fandom Developers Wiki, and semi-official Templates Wiki occasionally improve some of their documentation as well as adding new templates specifically designed for Fandom sites, and are therefore worth checking from time to time.

Copying templates from other wikis

Contributors throughout Fandom have made all different kinds of templates. It is often simpler to copy an existing template and modify it for your needs, rather than creating one from scratch. The Templates Wiki is a good place to start looking for a template that fits your needs, though an established wiki for a closely related subject to that of your wiki may already have the template you need.

In most cases, you are free to copy templates based on the shared CC-BY-SA license, but make sure the community you want to copy from does not have an alternative licensing scheme that may place restrictions on what you can copy. Giving credit to the community which you copied the template from is recommended and would likely be appreciated by that community.

Here are some basic steps to copy most templates:

  1. Find the template you want to copy (usually https://wikiname.fandom.com/wiki/Template:templatename).
  2. Click the Edit button, select all of the wikitext, and copy it.
  3. Create a new template page on your community (https://yourwiki.fandom.com/wiki/Template:templatename?action=edit).
  4. Paste the wikitext code you copied and press the Publish button.

Many templates have a separate subpage for documentation about the template, normally in <nowiki> tags. Fortunately, the location is often standardized, so it is easy to copy the documentation as well. If you notice the template page you copied above does not look like the original, it is likely the documentation is on a separate subpage:

  1. Find the template documentation you want to copy (usually https://wikiname.fandom.com/wiki/Template:templatename/doc).
  2. Click the "Edit" button, select all the wikitext and copy it.
  3. Create a new template documentation subpage page on your community (https://yourwiki.fandom.com/wiki/Template:templatename/doc?action=edit).
  4. Paste the wikitext code you copied and press the Publish button.

Previewing edited template

If using the source or classic edit modes, it is desirable to preview any template you have edited. Normally you can then click "Publish" from the preview screen. VisualEditor will show the template by default.

See also

Further help and feedback

Community content is available under CC-BY-SA unless otherwise noted.