Interface administrators, smwadministrator, smwcurator, smweditor
82,369
edits
| 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 | *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. | ||
<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. | |||
*The coding looks like so: | *The coding looks like so: | ||
<nowiki>{{#if: peanut butter|make sandwich|starve}} </nowiki> | <nowiki>{{#if: peanut butter|make sandwich|starve}} </nowiki> | ||
*To explain the code: | *To explain the code: | ||
:*First, this bit of code is enclosed with <nowiki>{{}}</nowiki>. | :*First, this bit of code is enclosed with <nowiki>{{}}</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. | ::Following the first <nowiki>{{ is #if:</nowiki>. 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. | ||
*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.” | *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.” | ||
*So if there is NO peanut butter, you can leave the space is blank like so: | *So if there is NO peanut butter, you can leave the space is blank like so: | ||
| Line 272: | Line 270: | ||
*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. | *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." | *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: <nowiki>{{{president|}}}</nowiki>. Again the pipe makes the value zero. | ||
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: | 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: | ||
<nowiki>{{#if:{{{president|}}}|<td>'''President''':</td><td>{{{president}}}}}</nowiki> | <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 <nowiki>}}}}}</nowiki> 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. | ||
</ref>. | </ref>. | ||