ৱিকিপিডিয়া:Qif conditionals
এই প্ৰবন্ধটো অসমীয়া ৱিকিপিডিয়াৰ কেনেকৈ কৰিব নিৰ্দেশিকা-ৰ অন্তৰ্ভুক্ত। |
ParserFunctions allow for the conditional display of table rows, columns or cells (and really, just about anything else). But Parser functions have some limits.
Basic use
[সম্পাদনা কৰক]The following example shows a basic use for #if
:
{{#if:{{{variable_foo|}}} |foo is set to '''{{{variable_foo}}}''' |foo is ''blank''}}
Here, {{{variable_foo}}}
is checked to see if it is defined with a non-blank value. The table below shows the output from a template call (we'll call the template {{Conditional tables/example 1}}
) with different values for {{{variable_foo}}}
:
Template call | Result |
---|---|
{{Conditional tables/example 1}}
|
সাঁচ:Conditional tables/example 1 |
{{Conditional tables/example 1|variable_foo=}}
|
সাঁচ:Conditional tables/example 1 |
{{Conditional tables/example 1|variable_foo=value}}
|
সাঁচ:Conditional tables/example 1 |
Positional parameters {{{1}}} etc. work like named parameters:
{{#if:{{{1|}}} |1st parameter is '''{{{1}}}''' |1st parameter is ''blank''}}
Template call | Result |
---|---|
{{Conditional tables/example 1b| |bar}}
|
সাঁচ:Conditional tables/example 1b |
{{Conditional tables/example 1b|foo|bar}}
|
সাঁচ:Conditional tables/example 1b |
{{Conditional tables/example 1b|[[m:|not empty]]}}
|
সাঁচ:Conditional tables/example 1b |
{{Conditional tables/example 1b|bad=idea}}
|
সাঁচ:Conditional tables/example 1b |
{{Conditional tables/example 1b|1=ok=yes}}
|
সাঁচ:Conditional tables/example 1b |
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 entirely
[সম্পাদনা কৰক]It's also possible to hide rows of data within a table, however, there are issues you should be aware of.
Incorrect usage
[সম্পাদনা কৰক]Unfortunately #if
and the MediaWiki table syntax do not work together well. For example, the following, {{Conditional tables/example 2}} is invalid and will not work:
{| class="infobox" {{#if:{{{variable_foo|}}} | |- ! Foo | {{{variable_foo}}} }} |- ! Bar | {{{variable_bar}}} |}
The table below demonstrates the effect when {{Conditional tables/example 2}} is used:
Template call | Result |
---|---|
{{Conditional tables/example 2}} | সাঁচ:Conditional tables/example 2 |
{{Conditional tables/example 2|variable_foo=}} | সাঁচ:Conditional tables/example 2 |
{{Conditional tables/example 2|variable_foo=|variable_bar=bar}} | সাঁচ:Conditional tables/example 2 |
{{Conditional tables/example 2|variable_foo=value}} | সাঁচ:Conditional tables/example 2 |
{{Conditional tables/example 2|variable_foo=value|variable_bar=bar}} | সাঁচ:Conditional tables/example 2 |
The problem is with the usage of the pipe character (|
). This character, in template calls, is used to separate parameters and so is invalid.
Correct usage
[সম্পাদনা কৰক]Plan A
[সম্পাদনা কৰক]One method of hiding rows in tables (or other structures within tables) uses HTML directly.[1] 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
<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>
- this tag creates a caption (similar to|+
in MediaWiki table syntax)
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 {{Conditional tables/example 2a}}. As before, the table below demonstrates the effect when it's used:
Template call | Result |
---|---|
{{Conditional tables/example 2a}} | সাঁচ:Conditional tables/example 2a |
{{Conditional tables/example 2a|variable_foo=}} | সাঁচ:Conditional tables/example 2a |
{{Conditional tables/example 2a|variable_foo=|variable_bar=bar}} | সাঁচ:Conditional tables/example 2a |
{{Conditional tables/example 2a|variable_foo=value}} | সাঁচ:Conditional tables/example 2a |
{{Conditional tables/example 2a|variable_foo=value|variable_bar=bar}} | সাঁচ:Conditional tables/example 2a |
Plan B
[সম্পাদনা কৰক]As 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 Template:! (সম্পাদনা আলোচনা সংযোগ ইতিহাস). 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 {{Conditional tables/example 2b}}. As before, the table below demonstrates the effect when it's used:
Template call | Result |
---|---|
{{Conditional tables/example 2b|bar=nobar}}
|
সাঁচ:Conditional tables/example 2b |
{{Conditional tables/example 2b|foo=|bar=vbar}}
|
সাঁচ:Conditional tables/example 2b |
{{Conditional tables/example 2b|foo=value}}
|
সাঁচ:Conditional tables/example 2b |
{{Conditional tables/example 2b|foo=value|bar=vbar}}
|
সাঁচ:Conditional tables/example 2b |
Getting help
[সম্পাদনা কৰক]If 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 also
[সম্পাদনা কৰক]For avoiding blank rows in the case of successive optional rows, see m:Help:Table#Conditional_table_row.
For more information on #if
(and other # functions), see:
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:
- Template:Infobox - a "generic" infobox template which demonstrates these methods.
Notes and references
[সম্পাদনা কৰক]- ↑ Using HTML table code in templates can make them non-portable to other MediaWiki wikis. This is because Wikipedia and other Wikimedia Foundation wikis process wikitext through HTML Tidy; most other wikis do not have the same setup, and the HTML table tags do not render. See Wikipedia:WikiProject Transwiki#Special templates.