GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing en.wikipedia.org — Help:Conditional tables - Wikipedia
There are three ways to conditionally display or hide rows within a table. All of the methods involve the use of parser conditionals, in particular, the parser #if statement (see the § Refresher section) to conditionally include or exclude a row, depending on the value of some expression. MethodsCSS display:none propertyThe simplest option is to use the conditional with the CSS "display:none" property: {| class="wikitable" |- {{#if: {{{variable_foo|}}} | | style="display: none;" }} ! Foo | {{{variable_foo}}} |- ! Bar | {{{variable_bar}}} |} The code above is in {{Conditional tables/example 2c}}. The table below demonstrates the effect when it is used:
Pros and cons: with this method, there is no need for the wikitable pipe character to appear in the #if conditional, thus avoiding issues with escaping the vertical bar . However, sources and notes referred to in the hidden cells won't get suppressed with the other contents, so they will continue to be listed at the end of an article without any references to them occurring in the article's text. HTML tablesOne method of hiding rows in tables (or other structures within tables) uses HTML directly.[1] In general, there are only a handful of HTML tags you need to be aware of
A sample HTML table with a conditional row based on testing a template variable with #if follows: {| class="wikitable" {{#if:{{{variable_foo|}}} |<tr><th>Foo</th><td>{{{variable_foo}}}</td></tr>}} |- ! Bar | {{{variable_bar}}} |} The code above is in {{Conditional tables/example 2a}}. As before, the table below demonstrates the effect when it's used:
Vertical bar escapingBecause the parser function #if and MediaWiki table syntax do not work together well, the template code described at § Pitfalls with an illustration of non-working code at Example 2 will not work correctly. The problems there can be rectified by properly escaping the vertical bar. For most characters, often it's good enough to replace a problematic characters with the corresponding HTML entities, e.g. "{" by {, "|" by |, and "}" by }. But for Wiki tables a real vertical bar character "|" is required — using | HTML entity does not work. A simple trick allows to protect the "|" in template parameter values while still arriving as real "|" delimiter in the Wiki table, see the magic word {{!}}. 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="wikitable" {{#if:{{{foo|}}}| {{!}}- ! Foo {{!}} {{{foo}}} }} |- ! Bar | {{{bar}}} |} The code above is in {{Conditional tables/example 2b}}. As before, the table below demonstrates the effect when it's used:
Refresher on parser functionsFurther information: mw:Help:Magic words § Parser functions, and mw:Help:Extension:ParserFunctions
Conditional parser functions like #if allow for the conditional display of table rows, columns or cells, but they have some limits. The following example shows a basic use for {{#if: {{{variable_foo|}}} |foo is set to '''{{{variable_foo}}}''' |foo is ''blank'' }} Here,
Positional 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. PitfallsParser functions and table syntaxUnfortunately {| class="wikitable" {{#if:{{{variable_foo|}}} | |- ! Foo | {{{variable_foo}}} }} |- ! Bar | {{{variable_bar}}} |} The table below demonstrates the effect when {{Conditional tables/example 2}} is used:
The problem is with the usage of the pipe character ( 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 an editor via IRC. 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: Notes and references
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |