Open main menu

Changes

Template:Infobox/doc

197 bytes added, 15:24, 2 October 2013
Note that although there is no limitation on the number of rows available, row parameters should not be numbered more than 50 apart. See the [[#Limitations]] section below for more details.
===== Making data fields optional =====
A row with a label but no data is not displayed. This allows for the easy creation of optional infobox content rows. To make a row optional use a parameter that defaults to an empty string, like so:
For more on #if, see [[meta:ParserFunctions##if:|here]].
===== Hiding headers when all data fields are hidden =====
You can also make headers optional in a similar way. If you want a header to appear only if one or more of the data fields that fall under it are filled, one could use the following pattern as an example of how to do it:
{{Infobox
|name = Infobox/doc |title = Example of an optional header |header1 = {{#if:{{{item_oneitem1|}}}{{{item_twoitem2|}}}{{{item_threeitem3|}}}|Optional header}} | label2 = Item one 1 | data2 = {{{item_oneitem1|}}} | label3 = Item two 2 | data3 = {{{item_twoitem2|}}} | label4 = Item three 3 | data4 = {{{item_threeitem3|}}} | header5 = Static header | label6 = Static item | data6 = Static value
}}
<pre style="overflow:auto">
{{Infobox
|name = {{subst:PAGENAME}} |title = Example of an optional header |header1 = {{#if:{{{item_oneitem1|}}}{{{item_twoitem2|}}}{{{item_threeitem3|}}}|Optional header}} | label2 = Item one 1 | data2 = {{{item_oneitem1|}}} | label3 = Item two 2 | data3 = {{{item_twoitem2|}}} | label4 = Item three 3 | data4 = {{{item_threeitem3|}}} | header5 = Static header | label6 = Static item | data6 = Static value
}}
</pre>{{clear}}
header1 will be shown if any of item_oneitem1, item_twoitem2, or item_three item3 is defined. If none of the three parameters are defined the header won't be shownand no emty row appears before the next static content.
The trick to this is that the "if" returns false only if there is nothing whatsoever in the conditional section, so only if all three of item_one, item_two and item_three are undefined will the if statement fail.
Anonymous user