User:Addyrielle/Conditional tables
Here's some more notes from the wiki!
ParserFunctions allow for the conditional display of table rows, columns or cells.
Basic use for #if
{{#if:{{{variable_foo|}}}
|foo is set to '''{{{variable_foo}}}'''
|foo is ''blank''}}
^ This gets checked to see if the foo variable is blank. Eg:
Template call | Result |
---|---|
{{if_example_1}} | foo is ''blank'' |
{{if_example_1|variable_foo=}} | foo is ''blank'' |
{{if_example_1|variable_foo=value}} | foo is set to '''value''' |
Positional parameters {{{1}}} etc. work like named parameters:
{{#if:{{{1|}}}
|1st parameter is '''{{{1}}}'''
|1st parameter is ''blank''}}
Template call | Result |
---|---|
{{if_example_1/b| |bar}} | 1st parameter is blank |
{{if_example_1/b|foo|bar}} | 1st parameter is foo |
{{if_example_1/b|[[m:|not empty]]}} | 1st parameter is not empty |
{{if_example_1/b|bad=idea}} | 1st parameter is blank |
{{if_example_1/b|1=ok=yes}} | 1st parameter is ok=yes |
Note: The pipe symbol in the link works as is, it's not quite that easy within Wiki tables - it messes up. Use the method below to remedy this.
This method of hiding rows in tables (or other structures within tables) uses HTML directly. In general, there are only a few HTML tags you need to be aware of:
- <tr> - this tag creates a new row (similar to |- in MediaWiki table syntax).
- <th> - this tag creates a new header cell within a row (similar to ! in MediaWiki table syntax).
- <td> - this tag creates a new cell within a row (similar to | in MediaWiki table syntax).
- <caption><nowiki> - this tag creates a caption (similar to |+ in MediaWiki table syntax).
<nowiki>{| class="infobox"
{{#if:{{{variable_foo|}}}
|<tr><th>Foo</th><td>{{{variable_foo}}}</td></tr>}}
|
! Bar
| {{{variable_bar}}}
|}