Simple Templates

From mw.mh370.wiki
Jump to navigation Jump to search


A Guide to Using MediaWiki in a Hosted Environment

An instructional website by the developer of mh370wiki.net - a MediaWiki site about Malaysia Airlines Flight MH370.


Simple Templates

I view simple templates as those which do not use variables.

For the mh370wiki.net site I have a lot of useful components in the Template namespace. When these are transcluded into a page there is no need to include the namespace prefix.

A Short Line

I frequently use a short line to separate parts of a page. The html horizontal line


is full width by default and has no significant white space before or after.

My ShortLine is simple and reusable:-

<includeonly><div style="margin-left:20%; margin-right:20%; margin-top:1em; margin-bottom:1em;"><hr></div></includeonly>

If there was nothing else on the source page then the includeonly tags would not be needed. But I have kept a few previous versions, where I adjusted the white space, between noinclude tags.

To use the ShortLine I just transclude it with this instruction:-

{{ShortLine}}

And the result is this:-



Sub-page List

I have used sub-pages a lot. Sometimes it is helpful to get a list of sub-pages somewhere on the top page, so I can see what exists; to easily link to and open a sub-page; to check that each sub-page is linked from a parent page.

To display the list of subpages I can just place this code at a suitable place on a parent page:-

{{SubpageList}}

The template looks like this:-

<hr>
<h5>Note: This article has sub-pages:-</h5>
<p>{{Special:PrefixIndex/{{FULLPAGENAME}}/}}</p>

FULLPAGENAME is a variable in MediaWiki. There is a list of 'magic words' and variables at https://www.mediawiki.org/wiki/Help:Magic_words

See also https://www.mediawiki.org/wiki/Help:Subpages


A Signature

To 'sign' an article with my name I just write:-

{{Signature}}

The template is simple:-

<p style="width:90%; margin-left: auto; margin-right: auto; font-size:1em;  text-align:right;"><u>Grant</u></p>

The result is at the end of this page.


Category Pages

Category pages only need to belong to a parent category, but on the mh370wiki.net site I have used templates to provide extra information on each category page.

I have adapted the idea here and created a simple template named CategoryPage in the Template namespace:-

<h2>Category: {{PAGENAME}}</h2>
   <div class="header">
      <p>This page lists matches for the category <i>{{PAGENAME}}</i>. To navigate to a higher level in the category hierarchy, use the link below the list of sub-categories or pages.</p>
   </div> <!-- end header -->
<div style="margin-left:4.5em; margin-right:4.5em;">
   <p style="margin-left:auto; margin-right:auto; text-align: justify;">{{{CategoryDescription| }}}</p> 
</div>
<includeonly>[[Category:{{{ParentCategory| }}}]]</includeonly> <!-- prevent the template from being added to a category -->

For each template I also create instructions, like this:-

<h5>Usage</h5>
<p>Copy this code into each category page.</p>
{{CategoryPage
   |ParentCategory=
   |CategoryDescription=
}}
How it works

When the section between the {{ }} brackets is copied into an empty category page all you have to do is fill in the blanks after the =. Add the name of the parent category, and provide a description of what this current category is for.

The {{ }} brackets indicates that the enclosed section is to be transcluded. By default if a namespace is not stated then MediaWiki looks in the Template Namespace. There it will find the Template:CategoryPage and use the values for ParentCategory and CategoryDescription.

To prevent the template from being added to a category we have to make sure that [[Category: ]] does not apply to the template itself. Since the template is being transcluded we can use the to ensure that the enclosed section is processed only when the template is transcluded, and is not included on the template page.

For more about Transclusion see this category Category:Transclusion. The Category:Transclusion uses this template and provides a usage example.

The category pages on the mh370wiki.net website are more complex and are described on the page Complex Templates.


Grant