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: when 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
| style="border:1px solid black"| 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:
 * NOTICE the {{#if:{{{president|}}} added to 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 it is really not that hard. For further insight 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
But there is a problem with this coding. The Wiki does not like it and will not process it, unless we change some of the pipes to this little template: {{!}}. {{!}} is the same as a stand along pipe. In our infobox above we need to replace some of the pipe with it so our infobox will work. Here is the coding;
 * Our finished infobox should look like this:

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