Help:Wiki University HTML--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 even 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 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:
 * 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 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
 <
 * Our finished infobox should look like this:

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

We embed our template as normal with the parameters: 
 * 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 and there is no space to indicate something is missing.

Try these out


 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: