Vote button trans.png
April's Project of the Month
It's spring time. It's primary election season!
Click here to find all the information you'll need to cast your ballot.

Help:Basic template transclusion

From Ballotpedia
Jump to: navigation, search

Template transclusion is a key feature of most wiki pages we use. As a writer, you are exposed to multiple forms of template transclusion on almost every page you edit. This can be as simple as a Horizontal Navigational Template on the bottom of a page to a complex infobox or a template designed to incorporate key categories on a page. This page will highlight the various uses of template transclusion on the wiki and some tips and tricks for expanding your ability to include templates.

Template basics

Templates are used on the wiki to include consistent information across a broad spectrum of pages within a project. They allow you to incorporate information like navigational boxes, infoboxes or graphs and permit you to change that information on all of the pages that link to it by merely changing the code on the template page itself. They also allow you to place unique information on a page within a standardized format and pull that information for later use in a dpl. A few important things to remember about a template are:

  • All templates begin with the namespace "Template:".
  • There are various tools to control what information is transferred in a template, including:
  • <noinclude>...</noinclude> — the text between the noinclude tags will not be included when the template is transcluded (substituted)
  • <includeonly>...</includeonly> — the text between the includeonly tags will be transcluded (substituted), but will not be processed on the template's own page
  • <onlyinclude>...</onlyinclude> (not often used) — specifies that nothing on the page except what appears between the onlyinclude tags will be transcluded (substituted)

Transcluded information

Some templates allow you to include parameters which will be defined on the page on which you are calling the template. Often on wiki’s you will need to set up templates which are common amongst pages but which will contain specific pieces of information that are different, i.e. infoboxes. This can be done using three curly brackets, {{{TEXT}}}. For easy use, I’ll call these “parameters” and the text used to summon a template, a “template call”. It is important to note that three brackets ({{{TEXT}}}) create a parameter within a template, while two curly brackets ({{Text}}) are used to summon a template onto a page or to begin a parser function. This feature allows you to create consistently formatted tables, templates and DPL's but change the information included in them to be more page specific. A few things to note about parameters:


The template code reads:
This is my {{{Parameter}}} test. Hello {{{Target}}}.

The Template call reads:
{{Template name|Parameter=communication|Target=world}}

The template on page reads:
This is my communication test. Hello world.
  • Parameters are included with three curly brackets ({{{) on a template page: i.e. {{{Parameter}}}
  • To automatically define a parameter in the event that it is undefined on a page, use a pipe (|) after your parameter and define it: i.e. Definition
  • Parameters can be used within Templates that hold DPL's to change the dpl call for the page you are including it on.
  • Fixed Wiki Variables can be used as parameters to incorporate specific meta-information on a template, like the page name or time stamp. This will render the page name of the page on which you are including the template.

Shifting categories

One popular trick for using templates is to transclude specific categories by using a template. When you include information from a template onto a page, you include all of the designated information on that template, including categories. By including certain categories using templates you make it easier to use DPL's to pull the template information and make it easier to do major category revisions on pages.