|
ParserFunctions allow for the conditional display of table rows, columns or cells (and really, just about anything else). The method is fairly straightforward, but has some limitations which are worth explaining.
Basic useThe following example shows a basic use for
{{#if:{{{variable_foo|}}}
|foo is set to '''{{{variable_foo}}}'''
|foo is ''blank''}}
Here,
Positional parameters {{{1}}} etc. work like named parameters:
{{#if:{{{1|}}}
|1st parameter is '''{{{1}}}'''
|1st parameter is ''blank''}}
Note how the pipe symbol (vertical bar) in the link works as is, it's not quite that easy within Wiki tables, see below. Hiding rows entirelyIt's also possible to hide rows of data within a table, however, there are issues you should be aware of. Incorrect usageUnfortunately
{| class="infobox"
{{#if:{{{variable_foo|}}}
|
|-
! Foo
| {{{variable_foo}}}
}}
|-
! Bar
| {{{variable_bar}}}
|}
The code above is in {{if_example_2}}. The table below demonstrates the effect when it's used:
The problem is with the usage of the pipe character ( Correct usagePlan AOne method of hiding rows in tables (or other structures within tables) utilizes HTML directly. HTML is more complicated than MediaWiki table syntax, but not much more so. In general, there are only a handful of HTML tags you need to be aware of
Working from the invalid template example above, by switching to HTML we end up with the following code:
{| class="infobox"
{{#if:{{{variable_foo|}}}
|<tr><th>Foo</th><td>{{{variable_foo}}}</td></tr>}}
|-
! Bar
| {{{variable_bar}}}
|}
The code above is in {{if_example_2a}}. As before, the table below demonstrates the effect when it's used:
Plan BAs noted above the only problem is the vertical bar or pipe symbol within a template. Often it's good enough to replace problematic characters by numeric references, e.g. "{" by {, "|" by |, and "}" by }. But for Wiki tables a real "|" delimiter is required — using | doesn't work as delimiter. A simple trick allows to protect the "|" in template parameter values while still arriving as real "|" delimiter in the Wiki table, see . Note that "!" (exclamation mark) has no problems with templates, it's the other delimiter used in Wiki tables. Here's the code for plan B:
{| class="infobox"
{{#if:{{{foo|}}}|
{{!}}-
! Foo
{{!}} {{{foo}}}
}}
|-
! Bar
| {{{bar}}}
|}
The code above is in {{if_example_2b}}. As before, the table below demonstrates the effect when it's used:
Getting helpIf you find yourself unable to get a template to behave how you like, you can try asking on Village pump, placing a request at Requested templates, or contacting one of the editors listed below. See alsoFor avoiding blank rows in the case of successive optional rows, see m:Help:Table#Conditional_table_row. For more information on The following help topics deal with templates: This help topic deals with table design (since most templates use tables, this may be useful): And finally:
|
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License.
Mercedes Car
This site monitored by SitePinger.net