Help:Templates: Difference between revisions

Jump to navigation Jump to search
Extending, mostly related to editing + Links to advanced editing help
(Sectioning + Another secret to advanced editing)
(Extending, mostly related to editing + Links to advanced editing help)
Line 22: Line 22:
;Maintenace templates:  Maintenance templates are nearly without exception messagebox templates.  Their purpose is to aid the maintenance of the wiki and to point out things that need to be improved.
;Maintenace templates:  Maintenance templates are nearly without exception messagebox templates.  Their purpose is to aid the maintenance of the wiki and to point out things that need to be improved.


;Utility templates:Utility templates are often small, but very useful templates.
;Utility templates: Utility templates are often small, but very useful templates.
 
;Inline templates:  Templates that can be used within sentences and flowing text.


== Using templates ==
== Using templates ==
Line 52: Line 54:
== Editing templates ==
== Editing templates ==
=== Creating new templates ===
=== Creating new templates ===
To create a new template, please use the search function.  This way you will find if there already is a template with that name or if there is one with a very similar name.  If there is no template with that name you will be presented with the option to create that page.  Click on the red link to open up a edit window.
Consider giving the template a meaningful name.  If you are mimicking a template on another wiki, using its name might be a good idea.  If the template will be used very often it might actually be a good idea to use a very short name, but proper documentation will then be even more important.  Do note that parameter names are case sensitive except for the first character.
 
To create a new template, please start by using the search function.  This way you will find if there already is a template with that name or if there is one with a very similar name.  If there is no template with that name you will be presented with the option to create that page.  Click on the red link to open up a edit window.


Two important things to add to your template is template documentation, preferably using {{tl|informative template}} and if possible to put the template in a more fitting category than [[:Category:Templates]].
Two important things to add to your template is template documentation, preferably using {{tl|informative template}} and if possible to put the template in a more fitting category than [[:Category:Templates]].


Unless it is a very simple template it can be a good thing to start writing the documentation as this might help you figuring out the last few things in what you want the template to do, and then more or less use the documentation as reference when typing the template itself.
Unless it is a very simple template it can be a good thing to start writing the documentation as this might help you figuring out the last few things in what you want the template to do and how you want it to do that, and then more or less use the documentation as reference when typing the template itself.


Do remember that you can, and should use the preview button now and then, or at least one before saving, in order to catch any errors before saving.  While the template always can be fixed if there are errors it is better to have an extra preview than an extra edit.  Do note that the template will be lost if you do not save it.
Do remember that you can, and should use the preview button now and then, or at least one before saving, in order to catch any errors before saving.  While the template always can be fixed if there are errors it is better to have an extra preview than an extra edit.  Do note that the template will be lost if you do not save it.


=== Editing existing templates ===
=== Editing templates ===
Editing a template is often as easy as editing a normal wiki page.  Lets say you want to edit a template with the name ''what you always wanted to know''. Either search for the template using the template namespace like ''Template:What you always wanted to know'' or click on a link to get you there.
Editing a template is often as easy as editing a normal wiki page.  Lets say you want to edit a template with the name ''what you always wanted to know''. Either search for the template using the template namespace like ''Template:What you always wanted to know'' or click on a link to get you there.


Line 66: Line 70:


Always try to add documentation to templates missing that, preferably using {{tl|informative template}}.
Always try to add documentation to templates missing that, preferably using {{tl|informative template}}.
=== Passing unnamed parameters ===
Passing parameters to templates make them a lot more useful.  Unnamed parameters can be used in the order they are passed, in essence <tt><nowiki>{{{1}}}</nowiki></tt>, <tt><nowiki>{{{2}}}</nowiki></tt> etc.  Consider the following template ''Template:Hello'':
<pre>Hello, {{{1|}}}{{{2|stranger}}}!</pre>
Its usage
<nowiki>{{</nowiki>'''hello'''<nowiki>|</nowiki>''title''<nowiki>|</nowiki>''name''<nowiki>}}</nowiki>
And an example
<pre>{{hello|Dr.|Falken}}</pre>
Hello, Dr. Falken!
You might wonder what that vertical stroke and the text following, <tt><nowiki>{{{</nowiki>1'''|'''<nowiki>}}}{{{</nowiki>2'''|stranger'''<nowiki>}}}</nowiki></tt>, in ''Template:Hello'' does.  Some of you might already have guessed that they are default values.  At least having an ''empty'' default value is a good practice, as a template otherwise will break when passed an empty parameter.  This happens if the above template is used without parameters
<pre>{{hello}}</pre>
Hello, stranger!
=== Passing named parameters ===
While using a template with named parameters can be a bit more of typing, they are not that much extra typing when editing a template.  They are however practical some other ways, they can be passed to a template in any order and, more important, they are named (as in not numbered).  That last thing makes them immensely more useful in complex templates.
Using them in a template are not that different than unnamed parameters.  Using the above template, but with named parameters, we could instead type
<pre>Hello, {{{title|}}}{{{name|stranger}}}!</pre>
Its usage
<nowiki>{{</nowiki>'''hello''' <nowiki>|</nowiki>''title='' <nowiki>|</nowiki>''name=''<nowiki>}}</nowiki>
And an example
<pre>{{hello |title=Dr. |name=Falken}}</pre>
Hello, Dr. Falken!


== Translating templates ==
== Translating templates ==
Line 79: Line 111:
While this page will not go into details, there is a few secrets to more advanced templates:
While this page will not go into details, there is a few secrets to more advanced templates:
;Tables:  Wiki tables are tricky to understand, but can do a lot for any kind of box template and small layouts.
;Tables:  Wiki tables are tricky to understand, but can do a lot for any kind of box template and small layouts.
;Magic words:  Magic words at first look like templates except for that they mostly are all uppercase.  One of them for example is <tt><nowiki>{{PAGENAME}}</nowiki></tt>, another one is <tt><nowiki>__NOTOC__</nowiki></tt>.
;Magic words:  Magic words at first look like templates except for that they mostly are all uppercase.  One of them for example is <tt><nowiki>{{PAGENAME}}</nowiki></tt>, another one is <tt><nowiki>__NOTOC__</nowiki></tt>.
;Parser functions:  Parser functions allow more or less regular programming with conditionals, switches, string formatting etc.  A good hint is that well placed empty html comments can make the code way more readable.
 
;HTML:  It might seem a bit funny to mention it, but sometimes you forget that you can use html in a MediaWiki wiki
;Parser functions:  Parser functions allow more or less regular programming with conditionals, switches, string formatting etc.  A good hint is that well placed empty html comments can make the code way more readable. One of them is <tt>#if</tt>, <tt><nowiki>{{</nowiki>'''#if:''' ''string'' | ''passed if non-empty'' | ''passed if empty'' <nowiki>}}</nowiki></tt>.
 
;HTML:  It might seem a bit funny to mention it, but sometimes you forget that you can use (some) html tags in a MediaWiki wiki.
 
;Cascading style sheets:  If parser functions can do magic for the functionality of a template CSS can do magic for its appearance.
;Cascading style sheets:  If parser functions can do magic for the functionality of a template CSS can do magic for its appearance.


== External links ==
== External links ==
* [http://www.mediawiki.org/wiki/Help:Templates MediaWiki template help]
* [http://www.mediawiki.org/wiki/Help:Templates MediaWiki template help]
* Advanced editing help at [http://www.mediawiki.org/wiki/Project:About MediaWiki]
** [http://www.mediawiki.org/wiki/Help:Tables Help:Tables]
** [http://www.mediawiki.org/wiki/Help:Magic_words Help:Magic words]
** [http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions Help:Extension:ParserFunctions]


[[Category:Help]]
[[Category:Help]]

Navigation menu