Help:Wiki University Wikitext--Infobox - If functions

Infobox Content

 * In our example from the last lesson, we had 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 a blank space for it.

If functions
|President | |  We know there are a lot of curly brackets here but pay close attention:
 * 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 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:
 * to this:
 * 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
With this coding, you can create a more complete infobox that covers all the items you think are necessary, but has the ability to shrink the infobox if not all the items are present, such as a vice president or a web site address.

Placing the extended infoboxes

 * Placing these longer infoboxes is done exactly as our example.
 * The difference: if nothing is entered after the equal sign, that line in the infobox will not show after it is posted or edited.

If function infobox

 * Our finished infobox should look like this:

Problem with coding
But there is a problem with this coding. The Wiki does gets a little confused by all the pipes and has a hard time figuring out which ones are for cells and which are part of the if function. To solve this little problem we can substitute this little template: | for some of the pipes. The | template is a builtin mini template which is the same as a stand alone pipe to cover this issue. In our infobox above we need to replace some of the pipes with it so our infobox will work. Here is the coding; We know that this looks like a real mess and difficult to follow. But this is what it take to get this kind of infobox to work.

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

We embed our template as normal:
 * NOTICE except for the name of the organization, the infobox is blank.

Here is what the finished infobox looks like without the hours entered:
 * NOTICE no hours were entered.


 * NOTICE no hours appear in the infobox.

Try these out


 Exercises

Use this coding for this exercise: Lets make this into a infobox: Check your answers
 * 1) Put a border around the infobox, limit the width to 190 pixels and make it so that 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.

 Quick Quiz
 * Parameters have two opening and closing curly brackets surrounding them.
 * A. True
 * B. False


 * Infoboxes usually are located at the top of the page on the right side.
 * A. True
 * B. False


 * Infoboxes are saved just like other templates but it is good practice to included the word "infobox" in its title.
 * A. True
 * B. False

Check your answers