Titan Network

More Titan Projects => ParagonWiki => Topic started by: Radionuclide on January 06, 2010, 10:06:21 PM

Title: Template Question
Post by: Radionuclide on January 06, 2010, 10:06:21 PM
Hi everyone,

I have a general wiki question.  I am trying to understand templates with parameters.  I have a good grasp on basic templates but, was thinking of using something on my department's wiki at work.

The idea is to create an info box similar to what wikipedia uses (example page http://en.wikipedia.org/wiki/Damin - on the right hand side).  This would set up a Quick Tips type thing:

Code: [Select]
{| class="infobox" style="border: 1px solid #aaa;border-left: 10px solid #bba;width: 25em; text-align: left; font-size: 95%; background:#fbfbfb"
|+ style="font-size: larger;" | '''Quick Tips'''
|-
| colspan="2" style="color:#ffffff;text-align:center;background:#1e90ff" | '''How To..'''
|-
! Step 1:
| Do this
|-
! Step 2:
| Do this
|-
! Step 3:
| Do this
|-
! Step 4:
| Do this
|-
! Step 5:
| Do this
|-
! Step 6:
| Do this
|-
! Step 7:
| Do this
|-
! Step 8:
| Do this
|-
| colspan="2" style="color:#ffffff;text-align:center;background:#1e90ff" | '''Notes'''
|-
! Note 1:
|-
| Blah blah
|-
! Note 2:
|-
| Blah blah
|-
|}

Obviously the amount of steps and notes and well as the content of both may change from page to page.  What I want is to be able to set-up to be reused.  You know the basic reason for a template  ;D

Now, I know that it can be done with parameters but, I have tried to read the help files on WikiMedia and seem to be missing something.  I'm not sure how to set some thing like this up.  Would any of you have the time to break it down for me?

This is not critical, just a nice to have (as well as an increase in my knowledge).

Thank you all in advance,
--Rad
Title: Re: Template Question
Post by: Sekoia on January 07, 2010, 12:26:12 AM
Suppose you want to call your template like this from an article:

Code: [Select]
{{directionsbox|step1=Wet hair.|step2=Apply shampoo.|step3=Lather.|step4=Rinse.|step5=Repeat}}
In your template, you need to put tokens in for each of the steps by surrounding with three braces, like this: {{{step1}}}. If you want a default value, you can also do it with a pipe, like this: {{{step1|omitted}}}, or {{{step1|}}} for blank. (Without a default, you'll see {{{step1}}} in the article if you dont' have step1= in the template call.)

So your template Template:Directionsbox might look like this:

Code: [Select]
{| class="infobox" style="border: 1px solid #aaa;border-left: 10px solid #bba;width: 25em; text-align: left; font-size: 95%; background:#fbfbfb"
|+ style="font-size: larger;" | '''Quick Tips'''
|-
| colspan="2" style="color:#ffffff;text-align:center;background:#1e90ff" | '''How To..'''
|-
! Step 1:
| {{{step1|omitted}}}
|-
! Step 2:
| {{{step2|omitted}}}
|-
! Step 3:
| {{{step3|omitted}}}
|-
! Step 4:
| {{{step4|omitted}}}
|-
! Step 5:
| {{{step5|omitted}}}
|}

However, if you want to be able to have a varying number of steps and only have just the right ones show up, it gets more complicated. You'd have to use the #if: parser function (which requires parse functions to be installed) and you'd have to be careful about escaping any | characters you use for the table. Take a look at the code for Infobox Contact (http://paragonwiki.com/wiki/Template:Infobox_Contact) for an example.
Title: Re: Template Question
Post by: Radionuclide on January 07, 2010, 06:02:52 PM
That certainly helps.  I'll look at #if a bit closer since that is what I want in the end but, I'll probably need to build up to it.. 

--Rad
Title: Re: Template Question
Post by: eabrace on January 07, 2010, 09:07:55 PM
Back when I first started tinkering with templates, Sekoia gave me this handy little link that I still find very useful:

http://www.mediawiki.org/wiki/ParserFunctions