To request editing rights on the Wiki, click here.

Help:Wiki University Wikitext--Infobox - If functions

From FamilySearch Wiki
Jump to navigation Jump to search

Lessons


Intermediate


Advanced


Flexbox


Additional Helps

Infobox Content[edit | edit source]

Name of Organization
Image goes here
President: President's name
Address: Address
Phone: Phone number
Hours Open: Hours opened
  • In our example from the lessons on infobox, we limited the items shown for our organization for illustration purposes.

  • But, as you know, many organizations have more offices and other items that would be worth knowing that should be included in these infoboxes.

  • It would be better to create an infobox with more items to cover all possibilities; however, the problem with this is the posted infobox would have a lot of blank spaces if the organization was small.

  • What we would like to happen is, if a parameter is not filled in, it does not appear in the infobox. In other words, if the organization does not have a phone number, there will not be a line or even a blank space for it.

If functions[edit | edit source]

  • It is possible to code the infobox so an item like "phone" does not appear if there is none.
  • We will now introduce you to an attribute called if functions.
  • It is a small bit of coding added to the title of the item in the first column.
  • This is an example of adding the if function code to the row for naming the President:

  • We go from this:
|President
|{{{president}}}

  • to this:
|{{#if:{{{president|}}}|President
|{{{president}}}}}

We know there are a lot of curly brackets here but pay close attention:

  • NOTICE the |{{#if:{{{president|}}} added ahead of the text in the first cell.
  • NOTICE the pipe after the first word "president."
  • NOTICE the two closing curly brackets at the end of where the name actually goes in the second cell.

This coding looks a bit intimidating but with a little practice, you will have it down pat. For more information than you will probably ever want to know about if functions see: if functions

You can create long infoboxes[edit | edit source]

With this coding, you can create a more complete infobox that has the ability to shrink down if not all the items are present, such as a vice president or a web site address.


If function infobox[edit | edit source]

  • Our finished infobox should look like this:

{| style="width:200px; border:1px solid black; float:right"
|-
|colspan="2" style="text-align:center"|{{{organization name|Name of Organization}}}
|-
|colspan="2" style="text-align:center"| {{#if:{{{image|}}}|{{{image|Place image here}}}}}
|-
|{{#if:{{{president|}}}|President:
|{{{president}}}}}
|-
|{{#if:{{{address|}}}|Address:
| {{{address}}}}}
|-
|{{#if:{{{phone|}}}|Phone:
| {{{phone}}}}}
|-
|{{#if:{{{hours open|}}}|Hours Open:
| {{{hours open}}}}}
|}


Problem with pipes[edit | edit source]

There is a problem with the coding above. The Wiki gets a little confused by all the pipes and has a hard time figuring out which ones are for the cells and which are part of the if function.

  • To solve this problem you can substitute this little template: {{!}} for some of the pipes.
  • The {{!}} template is a built-in mini template which was created to eliminate this confusion by Wikitext over pipes.
  • In our infobox above, we need to replace the pipes that introduce the cells with our {{!}} so our infobox will work[1].

Here is the coding;

{| style="width:200px; border:1px solid black; float:right"
{{!}}-
{{!}} colspan="2" style="text-align:center"|{{{organization name|Name of Organization}}}
{{!}}-
{{!}} colspan="2" style="text-align:center"| {{#if:{{{image|}}}|{{{image|Place image here}}}}}
{{!}}-
{{!}} {{#if:{{{president|}}}|President:
{{!}} {{{president}}}}}
{{!}}-
{{!}} {{#if:{{{address|}}}|Address:
{{!}} {{{address}}}}}
{{!}}-
{{!}} {{#if:{{{phone|}}}|Phone:
{{!}} {{{phone}}}}}
{{!}}-
{{!}} {{#if:{{{hours open|}}}|Hours Open:
{{!}} {{{hours open}}}}}
|}


We know this looks like a real mess and may be difficult to follow. But this is what it takes to get this kind of infobox to work with Wikitext coding. This is not a problem with HTML coding which is covered in the HTML course.

Embedding template[edit | edit source]

This is what the infobox looks like before we add information:

Name of Organization
  • NOTICE except for the name of the organization, the infobox is blank.

We embed our template as normal with the parameters:

{{FamilySearch Wiki Missionary infobox template

| organization name=Smith Family Assoc.
| image=[[File:Erastus Deaf Smith.JPG|180]]
| president=John Smith
| address= 1234 Hill St, Anytown, Anystate
| phone=360-555-1234
| hours open=

}}


  • NOTICE no hours were entered.

Here is what the finished infobox looks like without the hours entered:

Smith Family Assoc.
180
President: John Smith
Address: 1234 Hill St, Anytown, Anystate
Phone: 360-555-1234
  • NOTICE no hours appear in the infobox and there is no space to indicate something is missing.

Try these out[edit | edit source]

Tests.gif
Exercises

This will be a repeat of the last exercise with the addition of the material in this lesson. Try not to look back on the previous lesson to complete this exercise.

Use this coding for the exercise:

{|
|-
|organization name
|-
|image
|-
|President:
|president
|-
|Address:
|address
|-
|Phone:
|phone
|-
|Hours Open:
|hours open
|}

Let's make this into an infobox with the addition of the "if function" material:

  1. Put a border around the infobox, limit the width to 190 pixels and make it so that it will always be on the right side of the page.
  2. Put borders around each of the cells.
  3. Have the cells containing the words organization and image span both columns.
  4. Center the name of the organization and the image in their cells.
  5. Make the items in the right hand cells into parameters.
  6. Place the "if function" coding in the appropriate cells.
  7. Place the {{!}} where required.


Quick Quiz
  • If nothing is entered for a parameter, there will still be a space where the parameter would normally appear.
A. True
B. False
  • The "If function" allows you to create more complete infoboxes, but you do have to worry about them being too large and take up a lot of space if the subject to be posted in the infobox is small.
A. True
B. False
  • It does not matter whether you use regular pipes or {{!}} in infoboxes with if functions.
A. True
B. False
  1. This is not a problem if we create our infoboxes with HTML coding.