Help

Using Templates

From Beachapedia

Templates

What are templates?

Templates are bits of code or text on Beachapedia (or other MediaWiki-powered sites) that are designed to be used on multiple pages. Templates can display page text, or can contain non-visible elements like category assignments or other things that allow the software to organize pages and links.

Why would I use a template?

If you have a bunch of text that is the same (or similar) across multiple pages, it may be worth putting it in a template. With the text in a template, if the information changes, changing the template causes the text to be changed wherever it is used- be it on two, five, fifteen, or hundreds of pages.

How do I use a template?

If there is already a template that you would like to use, simply include the following code in the wikitext of the page you want it to appear on:

{{Template Name}}

Where are templates used on Beachapedia?

Templates are used everywhere. There is an article template which defines categories for pages that include it. There are also other templates for specific sections of the site (such as State of the Beach) which set up navigation bars, menus and links. In some cases, templates are even used as part of other templates.

What if the text isn't exactly the same?

Templates can also include variables. Variables are written into the text of the template and can be specified when you include the template code on the page it is included on. To use a variable, enclose the variable name in triple-curly braces inside the template like this:

Last year the state spent ${{{X}}} on beach fill projects.

Then when you put the template on a page, you specify the value for X:

{{Example Template
|X=200 Million
}}

The end result should appear on the page as:

Last year the state spent $200 Million on beach fill projects.

Can I use other pages as templates?

Absolutely. Before you create a template, you should make sure that it will act the way you expect and work the way you want it to. Any page can be used as a template, so before creating a page in the template namespace, you should put the content you want to be a template in a "sandbox" area under your user page. Click on your username at the top of the screen to access your user page, and then add "/Sandbox" (or whatever you want) to the end to create a subpage. Once you have entered the text you want, you can test it as a template by adding the following to the wikitext of the page you want it to appear on:

{{User:USERNAME/Sandbox}}

You can also include other pages in a page in the same manner. Just precede the name of the page you want to include with a colon inside the braces. To include the text for the Seawalls page, you would type:

{{:Seawalls}}

What if I want things to show up under certain conditions but not others?

Beachapedia has the "ParserFunctions" extension installed, and all of the functions that it offers can be used in templates. The help page for ParserFunctions offers examples and usage instructions for the various functions that are included. Some of these things may be a little tricky so some basic programming experience may be helpful if you want to use these. As an example, the ratings boxes for the various indicators under the State of the Beach report's State Reports pages use the ParserFunctions to highlight the line of the indicator for the page being viewed. The California Beach Access page demonstrates this and you can see how the highlight jumps as you move among the various indicator pages, despite the fact that they all use the same template.

What if I need more help?

Depending on what you are trying to do, a good place to start is the Mediawiki Template Help Page. It may also be worth looking around on Wikipedia or other wikis to see how templates are used. You can obviously also try asking one of the admins on Beachapedia to see if they can answer your question.