Difference between revisions of "Tutorial:AdvancedTutorialPage1i"

From WikiChem
Jump to: navigation, search
(Start page)
 
m (Add link)
 
(5 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
OK, you've now mastered most of the routine parts of MediaWiki.  What about using some bells and whistles?
 
OK, you've now mastered most of the routine parts of MediaWiki.  What about using some bells and whistles?
  
The first of these is the '''parser function'''.  With this feature, you can customize your template, by allowing you to input variables.  Take a look at '''[[:Template:ParserFunctionExample|this example]]'''.  With this:
+
The first of these is the '''[http://en.wikipedia.org/wiki/Help:Template template variable]''', which is a number or word surrounded by three curly brackets, such as <nowiki>{{{1}}}</nowiki>.  With this feature, you can customize your template, by allowing you to input different values for the template to process.  Take a look at '''[[:Template:Birthday|this example]]''', which has the following code (excluding the category info) on the template page:
 +
<nowiki>[[File:Birthday cake (fun).png|left|50px]]
 +
</nowiki>
 +
  <nowiki><span style="color:green">'''{{{Name}}}'''</span> has a birthday on {{{Month}}} {{{Date}}}!
 +
</nowiki>
 +
When you use this template on a page, the variables are named explicitly as '''''Name''''', '''''Month''''' and '''''Date'''''.  We can enter these parameters in any order, using the | symbol to separate them, thus:
  
  
These can quickly get quite ridiculous in the hands of a real expert - take a look at one of the most widely used templates on Wikipedia, '''[http://en.wikipedia.org/w/index.php?title=Template:WPBannerMeta&action=edit the WPBannerMeta template]'''. My brain can usually only handle a couple of variables, so let's try  
+
'''<nowiki>{{Birthday|Name=Michael Jones|Date=12th|Month=June}}</nowiki>''' produces
 +
 
 +
{{Birthday|Name=Michael Jones|Date=12th|Month=June}}
 +
 
 +
 
 +
You can also use unnamed parameters, in which case the variables must be entered in the standard order.  In these cases, the template contains numerical parser functions <nowiki>{{{1}}}, {{{2}}}</nowiki>, etc.
 +
 
 +
There are also certain '''[http://en.wikipedia.org/wiki/Help:Magic_words Magic words]''' that provide shortcuts to useful functions or data, such as TOCs, today's date, the page name, etc.
 +
 
 +
'''Parser functions''' provide a more elaborate way to work with template variables, using logic commands such as "If".  These can be quite simple, but they can quickly get quite ridiculous in the hands of a real expert - take a look at one of the most widely used templates on Wikipedia, '''[http://en.wikipedia.org/w/index.php?title=Template:WPBannerMeta&action=edit the WPBannerMeta template]'''.   
  
 
'''[[Tutorial:AdvancedTutorialPage1j|Next page]]'''
 
'''[[Tutorial:AdvancedTutorialPage1j|Next page]]'''
  
 
[[Category:Tutorial pages]]
 
[[Category:Tutorial pages]]

Latest revision as of 04:29, 24 May 2011

Wiki 3 bell image.jpg

OK, you've now mastered most of the routine parts of MediaWiki. What about using some bells and whistles?

The first of these is the template variable, which is a number or word surrounded by three curly brackets, such as {{{1}}}. With this feature, you can customize your template, by allowing you to input different values for the template to process. Take a look at this example, which has the following code (excluding the category info) on the template page:

[[File:Birthday cake (fun).png|left|50px]]

<span style="color:green">'''{{{Name}}}'''</span> has a birthday on {{{Month}}} {{{Date}}}!

When you use this template on a page, the variables are named explicitly as Name, Month and Date. We can enter these parameters in any order, using the | symbol to separate them, thus:


{{Birthday|Name=Michael Jones|Date=12th|Month=June}} produces

Birthday cake (fun).png

Michael Jones has a birthday on June 12th!



You can also use unnamed parameters, in which case the variables must be entered in the standard order. In these cases, the template contains numerical parser functions {{{1}}}, {{{2}}}, etc.

There are also certain Magic words that provide shortcuts to useful functions or data, such as TOCs, today's date, the page name, etc.

Parser functions provide a more elaborate way to work with template variables, using logic commands such as "If". These can be quite simple, but they can quickly get quite ridiculous in the hands of a real expert - take a look at one of the most widely used templates on Wikipedia, the WPBannerMeta template.

Next page