Author Topic: Template Question  (Read 2564 times)

Radionuclide

  • Underling
  • *
  • Posts: 9
Template Question
« 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
/whereami

Sekoia

  • Titan Network Admin
  • Elite Boss
  • *****
  • Posts: 1,848
Re: Template Question
« Reply #1 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 for an example.

Radionuclide

  • Underling
  • *
  • Posts: 9
Re: Template Question
« Reply #2 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
/whereami

eabrace

  • Titan Moderator
  • Elite Boss
  • *****
  • Posts: 4,291
Re: Template Question
« Reply #3 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
Titan Twitter broadcasting at 5.000 mWh and growing.
Titan Facebook

Paragon Wiki admin
I was once being interviewed by Barbara Walters...In between two of the segments she asked me..."But what would you do if the doctor gave you only six months to live?" I said, "Type faster." - Isaac Asimov