Interface administrators, smwadministrator, smwcurator, smweditor
82,369
edits
| Line 256: | Line 256: | ||
<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>. | |||
*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 | *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 a positive value, the browser picks the first option, “make sandwich” if there is no value or no peanut butter, 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 really is NO peanut butter, you can leave the space is blank like so: | ||
<nowiki>{{#if(blank)|make sandwich|starve}}</nowiki> and it picks the second option which is starvation. | <nowiki>{{#if(blank)|make sandwich|starve}}</nowiki> and it picks the second option which is starvation. | ||
*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: | *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: | ||
| Line 270: | 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 | *For our template, we are assuming that there are no values for any of the items in the infobox. This is the reason the parameters are coded like so, for example: <nowiki>{{{president|}}}</nowiki>. Again notice the pipe after the word "president" which 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 <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. | *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>.<br><br> | ||
*The next step is to put the coding for item you want to fill in with the infobox template like so: | *The next step is to put the coding for item you want to fill in with the infobox template like so: | ||
<table style="border:1px solid blue; "> | <table style="border:1px solid blue; "> | ||
<tr> | <tr> | ||
| Line 339: | Line 334: | ||
</tr> | </tr> | ||
</table> | </table> | ||
*What this coding means that if you do not put anything after the = sign on the President line, this item will not appear in the infobox. So if you have a long infobox but few items to fill in, the infobox will shrink up to fit the information you have added. | *What this coding means that if you do not put anything after the = sign on the President line, this item will not appear in the infobox. So if you have a long infobox but few items to fill in, the infobox will shrink up to fit the information you have added.<br><br> | ||
{{reflist}} | {{reflist}} | ||