Help:Understanding and Using Templates
From StcWiki
Contents |
[edit] Overview
This article describes common use of MediaWiki (MW) templates. MW templates are special pages having their own namespace, templates:. You create content in a given template page, and then insert that content in one or more wiki locations via a wiki template tag. A common misconception about templates is that you can edit the output content in the destination page, which is not true; content can only be edited in the template itself, which of course will modify every instance of that template's content used elsewhere in the wiki.
[edit] Starting a New Template Page
MediaWiki templates are a special kind of wiki pages, so naturally they have their own namespace, template:. Like all pages in MW, the easiest way to start a new template is to first create a link to it, e.g., [[template:New Template Title]]. If you want to use the new template in the same page you create the link (which is usually the case) then you can use double curly brackets instead, e.g., {{template:New Template Title}}. In the latter case, the syntax functions in a unique way, first as a link until you initially create the template (save something in the template page), and then as a template tag that inserts the saved template content in the same location the template tag is positioned.
When you need to edit your template, you go Special pages > All pages, select Templates from the namespace drop-down list options at top, and find the template in the list of existing templates displayed.
[edit] Inserting Template Content
In any instance (after initially creating the template) you want to insert template content in a given page, you do not need to use the "template:" namespace, you simply use the the curly brackets and the template page title, e.g., {{New Template Title}}, effectively a template tag. Template content will be inserted wherever the page is placed.
[edit] Templates for Navigation
Effective, attractive navigation, like with any web project, requires understanding of what you really need the navigation for. Most navigation schemes are structurally comprised of styled HTML lists, which, in the long run, is how it should be done here in the wiki too, though it's not necessary right now if just quick navigation functionality is needed. Most kinds of navigation schemes are reflected by one of the following three base forms:
- vertical navigation (a regular list, only of links)
- horizontal navigation (menu bars, breadcrumb trails, etc.)
- previous/next navigation
All of these (apparently even the last one) can be created using templates, and the first two are especially easy to do. We'll consider two quick and dirty approaches people can use right now (without too much concern for semantical HTML or CSS presentation).
[edit] Vertical List/Navigation Templates
In this case we'll create a sample template having three vertical lists, one for each list style MW allows you to easily create by default; namely, ordered lists, unordered lists (bullets), and indented lists with no bullet style at all.
We'll name this template template:Vertical List Template Example; go and have a look at it to see what's there. The link list you might create with such a template may not necessarily be for navigation; it simply might be a common list of links you want to have on multiple pages. If you wanted to use a list like this, you could copy the list style you wanted from this template (or simply create your own from scratch), create your new template as described above, paste the list content into the new template, change links as necessary, and save.
[edit] Horizontal Navigation Templates
When an HTML list is presented as a horizontal list using CSS, it's usually only done to serve as a bar of links (main menu, footer, breadcrumbs, etc.). As noted earlier, we should want to make any needed horizontal navigation bars this way, but it's not necessary to do so immediately; such link bars can easily be created now without worrying about semantical markup.
As demonstration, have a look at the contents of the template:Horizontal Navigation Template Example. This sample template is meant to show how a line of text (not a proper list) can be made to serve as a horizontal link bar...
You could copy such a bar, add your own links to it, change the color assignments, and call it good for a mini navigation set for a suite of associated pages. You could also arrange the links so they reflected a breadcrumb path from the main pages to the current page, as might be considered in the architecture of the wiki overall.
[edit] Custom Navigation Lists by Class Identification
If you can follow this part, great. If you can't, don't worry about it, it will be handled in time anyway without need for a lot of instruction.
You'll note in the example template just above that inline styles were used to give some color and shape to the link bar. This is a bloated and messy way to do it, really, because all those styling aspects (presentational aspects) should be put in the CSS style sheets (and the bar of links should really be created a a semantical list). In the future, once the wiki redesign is done, we'll create a few custom navigation list styles that people can use in their navigation templates. All they will need to do is copy a base list with the associated class or id selector and add their links as needed. Much easier and cleaner than trying to use inline styles every time. We also keep wiki elements looking more consistent this way too, so when one style change is made, it's made everywhere in the wiki for that selector.
[edit] Back/Forward Navigation
(It's not clear yet how this works, but it will be added when known.)
[edit] Templates for Page Messages
Pages messages are beneficial with respect to collaboration, or to give status indication of a pages content. As a real example of such a template, see the template:Work In Progress template. When needed, message templates are primarily put at the very top of pages so they're messages are immediately visible to page visitors.
[edit] Templates for Flagging Content Inline
Unlike message templates that are used at tops of pages, inline flags are often just tempates that deliver a single word that gives attention or status to something inline. A good example is a "New" flag to indicate something is newly added.
It might seem that adding a template tag simply to give a one-word flag on some inline content is overkill, but again, it's a great way to ensure that the flag has the same presentation everywhere it's used across multiple authors.

