How to Create an Infobox: Difference between revisions

m
Line 252: Line 252:
*Notice that there are <font color="red">{{ }}</font color> at each end of the expression.  That means it is a mini template.
*Notice that there are <font color="red">{{ }}</font color> at each end of the expression.  That means it is a mini template.
*After the first set of <font color="red">{{</font color> notice <font color="red">#if:</font color> which consists of a pound sign <font color="red">#</font color>, the word <font color="red">if</font color> and a colon <font color="red">:</font color>.
*After the first set of <font color="red">{{</font color> notice <font color="red">#if:</font color> which consists of a pound sign <font color="red">#</font color>, the word <font color="red">if</font color> and a colon <font color="red">:</font color>.
*After the colon you see the parameter repeated with the addition of a pipe after the word inside the {{{}}} and a pipe on the outside like so:<font color="red"><nowiki>{{{parameter|}}}|</nowiki></font color>.  We will not take the time to explain what all this code means but if you are interested see the footnote<ref>The coding looks complicated but it is really not.  First this is an “if” statement.  In essence, it says “if” you have A do B or if you do not, do C.  Or another way to put it, if you have peanut butter, make a sandwich otherwise starve.   
*After the colon you see the parameter repeated with the addition of a pipe after the word inside the {{{}}} and a pipe on the outside like so:<font color="red"><nowiki>{{{parameter|}}}|</nowiki></font color>.  We will not take the time to explain what all this code means but if you are interested see the footnote
The coding looks like so:
 
{{#if: peanut butter|make sandwich|starve}}  
<ref>The coding looks complicated but it is really not.  First this is an “if” statement.  In essence, it says “if” you have A do B or if you do not, do C.  Or another way to put it, if you have peanut butter, make a sandwich otherwise starve.   
To explain the code:
*The coding looks like so:
First, this bit of code is enclosed with {{}}.
<nowiki>{{#if: peanut butter|make sandwich|starve}} </nowiki>
Following the first {{ is #if:.  This code tells the browser that a “if” statement is coming.  For our peanut butter example, the question is, do we have any peanut butter? This test statement or called a “test string,” is separated from our two options with a pipe. Our first option is to “make a sandwich.”  The second option is to “starve.”  The two options themselves are separated by a pipe.
*To explain the code:
This coding is testing to see if there is a positive value in the test string or if there is any peanut butter.  If there is, the browser picks the first option, “make sandwich” if not, it picks the second option “starve.”
:*First, this bit of code is enclosed with <nowiki>{{}}</nowiki>.
So if there is NO peanut butter, you can leave the space is blank like so:
::Following the first {{ is #if:.  This code tells the browser that a “if” statement is coming.  For our peanut butter example, the question is, do we have any peanut butter? This test statement or called a “test string,” is separated from our two options with a pipe. Our first option is to “make a sandwich.”  The second option is to “starve.”  The two options themselves are separated by a pipe.
{{#if(blank)|make sandwich|starve}} and it picks the second option which is starvation.
*This coding is testing to see if there is a positive value in the test string or if there is any peanut butter.  If there is, the browser picks the first option, “make sandwich” if not, it picks the second option “starve.”
Now what if we do not want the word “starve” to show at all?  What if we do not even want to mention peanut butter if there isn’t any.  Well, enter the code in this manner:
*So if there is NO peanut butter, you can leave the space is blank like so:
{{#if(blank)|make sandwich}} result: (blank line).   
<nowiki>{{#if(blank)|make sandwich|starve}}</nowiki> and it picks the second option which is starvation.
Notice the second option is left out.  With the second option missing the browser’s only choice is to ignore the whole line of code and give us a blank line.
*Now what if we do not want the word “starve” to show at all?  What if we do not even want to mention peanut butter if there isn’t any.  Well, enter the code in this manner:
In our coding for creating this infobox, we are using parameters which are enclosed by {{{}}}.  To show a non value for peanut butter instead of leaving a blank space, we add the pipe after the word “peanut butter” like so:  
<nowiki>{{#if(blank)|make sandwich}}</nowiki> result: (blank line).   
{{{peanut butter|}}}.  This bit of coding assumes there is NO peanut butter.
*Notice the second option is left out.  With the second option missing the browser’s only choice is to ignore the whole line of code and give us a blank line.
So our coding will look like so:
*In our coding for creating this infobox, we are using parameters which are enclosed by <nowiki>{{{}}}</nowiki>.  To show a non value for peanut butter instead of leaving a blank space, we add the pipe after the word “peanut butter” like so:  
{{#if:{{{peanut butter|}}}|make sandwich}}.
<nowiki>{{{peanut butter|}}}</nowiki>.  This bit of coding assumes there is NO peanut butter.
Because of the pipe after the word peanut butter, the test string is a non value or there is no peanut butter and so the browser goes looking for the second option.  But since there is no second option, whole bit of code is ignored and a blank line is returned to the browser.
*So our coding will look like so:
But if there is some peanut butter available, then the first option is displayed or in our case “make a sandwich.
<nowiki>{{#if:{{{peanut butter|}}}|make sandwich}}</nowiki>.
*Because of the pipe after the word peanut butter, the test string is a non value or there is no peanut butter and so the browser goes looking for the second option.  But since there is no second option, whole bit of code is ignored and a blank line is returned to the browser.
*But if there is some peanut butter available, then the first option is displayed or in our case "make a sandwich."
For our template, we are assuming that there is no value for any of the items in the infobox.  This is the reason the parameters are coded like so, for example: {{{president|}}}.  Again the pipe makes the value zero.   
For our template, we are assuming that there is no value for any of the items in the infobox.  This is the reason the parameters are coded like so, for example: {{{president|}}}.  Again the pipe makes the value zero.   
In our coding for our template, the first option is this whole statement: <td>President:</td><td>{{{president}}}.  The second option is left out.  So the whole bit of coding looks like this:
In our coding for our template, the first option is this whole statement: <nowiki><td>President:</td><td>{{{president}}}</nowiki>.  The second option is left out.  So the whole bit of coding looks like this:
{{#if:{{{president|}}}|<td>'''President''':</td><td>{{{president}}}}}
<nowiki>{{#if:{{{president|}}}|<td>'''President''':</td><td>{{{president}}}}}</nowiki>
Notice the 5 }}}}} curly brackets at the end of the line of code.  It is really ending three }}} curly brackets for the parameter and the two ending curly brackets for the if statement.  Probably clearer if we rendered it as }}} }} with a space between the three and the two curly brackets.  You can do this and it will not effect the code.
Notice the 5 }}}}} curly brackets at the end of the line of code.  It is really ending three }}} curly brackets for the parameter and the two ending curly brackets for the if statement.  Probably clearer if we rendered it as }}} }} with a space between the three and the two curly brackets.  You can do this and it will not effect the code.
The net result, if a name is entered for president, then the first option is chosen and the office and name of president is displayed.  If nothing is entered for the name the second option is chosen and the browser returns a blank line.
The net result, if a name is entered for president, then the first option is chosen and the office and name of president is displayed.  If nothing is entered for the name the second option is chosen and the browser returns a blank line.
Interface administrators, smwadministrator, smwcurator, smweditor
82,369

edits