Help:Editing/Template

Jump to navigation Jump to search

A template is a page that gets included in another page, this other page is said to transclude the template. Templates are used for text that is often repeated, then only the template needs to be updated.

Simple templates

For example, create a page called Template:Main article with the text

The main article for this is at [[{{{1}}}]].

and then to use the template insert "{{Main article|Whatever}} where you want that text to appear.

To include the page where the template is used in some category, without that template being included in the same category, use <includeonly></includeonly> tags and for text on the template page to be excluded on the target page use <noinclude></noinclude> tags.

<includeonly>
 ''The main article for this is at [[{{{1}}}]].''
 [[Category:Some category]]
 </includeonly>
 <noinclude>
 Some documentaion here.
 [[Category:Templates]]
 </noinclude>

Using templates from Wikipedia

Complex templates are easier obtained from Wikipedia, where considerable work has already gone into developing and debugging these. Use Special:Import to import from Wikipedia, (only administrators of a wiki can do this). Do not include the full history or the file will become too large. Check Include all templates and transcluded pages so that any dependencies are included. Also be sure to copy any relevant styling to MediaWiki:Common.css.

Customisation

Be sure to check for and copy any required JavaScript from MediaWiki:Common.js and any relevant styling from MediaWiki:Common.css. Site specific templates need to be made more generally usable, as follows:

  • Replace instances of Wikipedia in the text with {{ns:Project}}, (or Miraheze if appropriate).
  • Replace instances of WikiMedia in the text with Miraheze.
  • Replace namespace wikilinks e.g. Wikipedia to {{ns:Project}} or meta.

In Lua modules replace Wikipedia with ' .. mw.site.siteName .. ' for example to alter the text in {{stub}} change in module asbox line 233 from:

' is a [[Wikipedia:stub|stub]]. You can help Wikipedia by [',

to:

' is a [[' .. mw.site.namespaces.Project.name .. ':stub|stub]]. You can help ' .. mw.site.siteName .. ' by [',
.
  • Remove assumptions about the structure of the wiki (such as a template producing an error when used in certain namespaces - you can't know what namespace configuration the target wiki will use) from both the code and the documentation.
  • Remove or import (making sure to follow this process again) any dependencies that don't exist here.
  • Remove any red-linked categories and add the template to Category:Templates or an appropriate subcategory.

Icons

Synth DIY Wiki is Instant Commons enabled, otherwise the images for icons would have to be uploaded locally. A good source for icon images is Wikimedia Commons' Category:Icons by subject.

Licensing

Because of CC-BY-SA licensing considerations the previous authors need to be acknowledged. Insert the appropriate source and attribution template at the bottom of the imported pages, (but not sub-pages) e.g. before </noinclude> from Category:Attribution templates.

Testing

For previewing a template do the following:

  1. Copy the templates to be tested under a common prefix. For example, you might copy Template:Foo to User:Example/sandbox/Template:Foo. Alternatively, you might create User:Example/sandbox/Template:Foo as a redirect to Template:Foo/sandbox.
  2. Go to Special:TemplateSandbox. Fill in the page or revision to be rendered, and the prefix you chose in step 1. It is possible to specify multiple prefixes by separating them using vertical bars, e.g. User:Example/sandbox1|User:Example/sandbox2.
  3. Click View.

There is also a box at the bottom of the edit form which allows for previewing some other page as it would appear were the template being edited saved with the current contents of the edit form.

See also