Help:Template

From CCS Cataloging Manual
Jump to navigation Jump to search

Templates are standard wiki pages whose content is designed to be transcluded (embedded) inside other pages. Templates follow a convention that the name is prefixed with "Template:", assigning it to that namespace. Otherwise, you can create them like any other wiki page.

Usage

{{Name}} 'transcludes' (i.e. embeds or includes a copy of) the content of the template (stored in the page Template:Name) whenever a page with the template embedded in it is fetched and displayed; i.e. if the template is later changed, all pages that use that template will automatically change too.

For example, the page Template:Sortable includes the text:

border="1" cellpadding="4" cellspacing="0" style="border:#c9c9c9 1px solid; margin: 1em 1em 1em 0; border-collapse: collapse;" class="sortable"

Therefore, if you use the page name surrounded by double braces, that is, {{Sortable}} or {{Template:Sortable}}, the contents of that template will be inserted in that spot when the current page is loaded. (Note that, as with any wiki link, the case of the first letter of the page name is always converted to uppercase before being processed and thus does not matter; that is, {{sortable}} functions exactly the same as {{Sortable}}.)

In other words, this wiki page source:

{| {{sortable}}
! Column A !! Column B
|-
| 1 || 2
|-
| 3 || 4
|}

will be displayed to the end user as if the source code were this:

{| border="1" cellpadding="4" cellspacing="0" style="border:#c9c9c9 1px solid; margin: 1em 1em 1em 0; border-collapse: collapse;" class="sortable"
! Column A !! Column B
|-
| 1 || 2
|-
| 3 || 4
|}

and any changes to the included portion of the Template:Sortable page will automatically immediately affect any pages that include the {{sortable}} link.

Include and noinclude

In a template, you can control what data from the template is included or not included in other pages by using the <noinclude> and <includeonly> tags.

  • Anything between <noinclude> and </noinclude> will be processed and displayed only when the template's page is being viewed directly.
  • Anything between <includeonly> and </includeonly> will be processed and displayed only when the page is being included. The most common application of this is to add all pages containing a given template to a category, without putting the template itself into that category.
  • Anything that is not inside either of those pairs of tags will be processed and displayed both when the template is included in another page, and when the template itself is viewed directly via navigating to Template:Template_Name.

Note: when you change the categories applied by a template, the categorization of the pages that use that template may not be updated until some time later: this is handled by a special MediaWiki function that runs periodically.

Available templates

List of Catalogers wiki templates