Help talk:Conditional tables: Difference between revisions

Content deleted Content added
Ywanght (talk | contribs)
Conditional columns: Mentioned in the intro, then not again afterward.
 
(21 intermediate revisions by 11 users not shown)
Line 1:
{{WikiProject banner shell|
{{Help Project}}
{{Wikipedia Help Project|class=start|importance=Low}}
==the problem of hiding rows in tables with background color==
}}
I use #if in a template to hide rows on some conditions. all works fine except the backgroud color.
I'd like to post the template's sample codes below:
<pre>
{|style="background-color:red;"
!<center>会议</center>
!<center>时间</center>
!<center>地点</center>
!<center>重要讲话</center>
!<center>关键词</center>
|-
|{{#if:{{{2014t|}}}|<center>2014年</center>
{{!}}{{{2014t}}}
{{!}}{{{2014p}}}
{{!}}[[{{{2014s}}}]]
{{!}}{{#if:{{{2014k|}}}|{{{2014k}}}|}}
|}}
|-
|{{#if:{{{2013t|}}}|<center>2013年</center>
{{!}}{{{2013t}}}
{{!}}{{{2013p}}}
{{!}}[[{{{2013s}}}]]
{{!}}{{#if:{{{2013k|}}}|{{{2013k}}}|}}
|}}
|-
|{{#if:{{{2012t|}}}|<center>2012年</center>
{{!}}{{{2012t}}}
{{!}}{{{2012p}}}
{{!}}[[{{{2012s}}}]]
{{!}}{{#if:{{{2012k|}}}|{{{2012k}}}|}}
|}}
|-
|{{#if:{{{2011t|}}}|<center>2011年</center>
{{!}}{{{2011t}}}
{{!}}{{{2011p}}}
{{!}}[[{{{2011s}}}]]
{{!}}{{#if:{{{2011k|}}}|{{{2011k}}}|}}
|}}
|}
</pre>
the background color seems strange at the top and the bottom of the table. anyone can help? thanks.
[[User:Ywanght|Ywanght]] ([[User talk:Ywanght|talk]]) 14:49, 4 March 2014 (UTC)
 
== MUST use HTML ==
 
Line 68 ⟶ 27:
:At least that was an exception that I thought worked. =) Regarding boolean templates, I have very little experience with those. If you think you can write up a basic beginners guide, be my guest. =) If not, I'll try and add that as I learn about them. —[[User:Locke Cole|Locke Cole]] • [[User talk:Locke Cole|t]] • [[Special:Contributions/Locke Cole|c]] 16:14, 17 March 2006 (UTC)
 
:: I tried to understand {{Lts|boolexists}} because I don't like {{Tl|Qif}} and want a simpler <ttsamp><nowiki>{{ifdef|test|do}}</nowiki></ttsamp>, but so far that failed. Some test results on [[Template talk:Boolexists]], note that these tests have nothing to do with the purpose of this template, i.e. test if a page exists. [[User:Omniplex|Omniplex]] 14:08, 19 March 2006 (UTC)
 
*: The point ''MUST use HTML'' turned out to be wrong, see below and {{Lts|!}}, it's more like ''MAY use XHTML''. [[User:Omniplex|Omniplex]] 11:20, 21 March 2006 (UTC)
Line 74 ⟶ 33:
== New attempt ==
 
:''Note: most of the templates referred to in this discussion have since been repurposed for other tasks.'' <font color="forestgreen">[[User:Happy-melon|'''Happy''']]</font>‑<fontb colorstyle="darkorangecolor: forestgreen;[[Media:Example.ogg]]">Happy</b>]]‑[[User talk:Happy-melon|'''<b style="color: darkorange;">melon''']]</fontb>]] 13:17, 26 September 2008 (UTC)
 
Mixing XHTML with Wiki table syntax is a layer violation, and some uses in {{Lcs|Wikipedia header templates}} for the shortcut are incorrect, <s>missing &lt;tr&gt; and similar issues, in other words FUBAR</s>.
But it should be possible to get it to work somehow with Wiki syntax.
 
Line 121 ⟶ 80:
:::::As straight forward as possible. [[User:Omniplex|Omniplex]] 22:31, 20 March 2006 (UTC)
 
::::You said ''AzaToth prefers (and I somewhat agree) using straight (X)HTML for table syntax (in other words, no wiki-markup at all).'' While I disagree strongly in the case of layer violations (either use Wiki or XHTML table syntax, but don't mix them) XHTML syntax and exclamation mark are no issues wrt {{Tl|Qif}}, only the vertical bar has to be escaped from the [[m:Help:Parameter default|parameter default]] mechanism. Normally <ttsamp>&amp;#124;</ttsamp> is good enough, but within a table it needs a template. I've created {{Lts|!}} for this purpose. [[User:Omniplex|Omniplex]] 22:20, 20 March 2006 (UTC)
 
== [[Template:Ifdef|Ifdef]] ==
Line 145 ⟶ 104:
|-
| valign="top" | {{tlx|qif_example_2/b}}
| valign="top" | <pre>{{qif_example_2/b}}</pre>
|-
| valign="top" | {{tlx|qif_example_2/b|foo&#61;}}
| valign="top" | <pre>{{qif_example_2/b|foo=}}</pre>
|-
| valign="top" | {{tlx|qif_example_2/b|foo&#61;|bar&#61;vbar}}
| valign="top" | <pre>{{qif_example_2/b|foo=|bar=vbar}}</pre>
|-
| valign="top" | {{tlx|qif_example_2/b|foo&#61;value}}
| valign="top" | <pre>{{qif_example_2/b|foo=value}}</pre>
|-
| valign="top" | {{tlx|qif_example_2/b|foo&#61;value|bar&#61;vbar}}
| valign="top" | <pre>{{qif_example_2/b|foo=value|bar=vbar}}</pre>
|}
 
Line 172 ⟶ 131:
it's so fragile. --&#160;[[User:Omniplex|Omniplex]] 16:17, 27 March 2006 (UTC)
 
Answered by [[User:Paddu|Paddu]] in [[Template talk:Ifdef|Ifdef]], executive summary: Use {{Tlx|ifdef|test|2&#61;then}} if '''then''' contains any "<ttsamp>=</ttsamp>". Minimalism has its drawbacks. --&#160;[[User:Omniplex|Omniplex]] 22:15, 17 April 2006 (UTC)
 
=== TfD nomination of Template:Ifdef ===
Line 204 ⟶ 163:
|-
| valign="top" | {{tlx|qif_example_2b}}
| valign="top" | <pre>{{qif_example_2b}}</pre>
|-
| valign="top" | {{tlx|qif_example_2b|foo&#61;}}
| valign="top" | <pre>{{qif_example_2b|foo=}}</pre>
|-
| valign="top" | {{tlx|qif_example_2b|foo&#61;|bar&#61;vbar}}
| valign="top" | <pre>{{qif_example_2b|foo=|bar=vbar}}</pre>
|-
| valign="top" | {{tlx|qif_example_2b|foo&#61;value}}
| valign="top" | <pre>{{qif_example_2b|foo=value}}</pre>
|-
| valign="top" | {{tlx|qif_example_2b|foo&#61;value|bar&#61;vbar}}
| valign="top" | <pre>{{qif_example_2b|foo=value|bar=vbar}}</pre>
|}
 
Line 280 ⟶ 239:
I've updated the instructions to use <code>#if</code> instead of {{tl|qif}}. The only loose-end that remains is updating {{tl|Infobox}} (which is still referenced in these docs) and deciding upon a new name for this page. Originally I planned on moving this to [[Wikipedia:If conditionals]], but maybe [[Wikipedia:ParserFunctions conditionals]] would be more appropriate (and would allow for later expansion to include examples using <code>#ifeq</code>, <code>#ifexpr</code> and so forth)? Or perhaps a more generic name, like [[Wikipedia:Template conditionals]]? Comments welcome, also, if anyone notices anything I missed in the article, please correct. =) —[[User:Locke Cole|Locke Cole]] • [[User talk:Locke Cole|t]] • [[Special:Contributions/Locke Cole|c]] 05:47, 17 April 2006 (UTC)
 
:I've added a caveat about "'''<ttsamp>=</ttsamp>'''" and positional parameters. Where {{tlx|ifdef}} works (no '''else''' needed) it's unnecessary to replace it by '''#if:''' (and v.v.). Renaming {{Lps}} is tricky, what about all its links and the shortcut? --&#160;[[User:Omniplex|Omniplex]] 23:25, 17 April 2006 (UTC)
::The only trouble with renaming this page is handling any double redirects that crop up. I don't think there'll be many though. =) Redirects from here to whatever new name is chosen will handle the rest. —[[User:Locke Cole|Locke Cole]] • [[User talk:Locke Cole|t]] • [[Special:Contributions/Locke Cole|c]] 16:27, 18 April 2006 (UTC)
:::Double redirects are shown, but what about dozens of <small><ttsamp><nowiki>[[w:Wikipedia:Qif&#160;conditionals]]</nowiki></ttsamp></small> on Meta? Maybe I even used <small><ttsamp><nowiki>[[w:WP:QIF]]</nowiki></ttsamp></small> or similar there. --&#160;[[User:Omniplex|Omniplex]] 00:47, 22 April 2006 (UTC)
::::As [[WP:QIF]] would be changed to point to the new name (and [[Wikipedia:Qif conditionals]] would also point to the new name) it shouldn't matter. —[[User:Locke Cole|Locke Cole]] • [[User talk:Locke Cole|t]] • [[Special:Contributions/Locke Cole|c]] 01:00, 22 April 2006 (UTC)
 
Line 301 ⟶ 260:
| <small><pre>{{#if: {{{tst}}} | -1- {{{1}}} }}</pre></small>
| {{#if: {{{tst}}} | -1- {{{1}}} }}
| <pre>{{ifdef | {{{tst}}} | -1- {{{1}}} }}</pre>
|-
| <small><pre>{{#if: {{{tst}}} | -2- {{{1|default}}} }}</pre></small>
| {{#if: {{{tst}}} | -2- {{{1|default}}} }}
| <pre>{{ifdef | {{{tst}}} | -2- {{{1|default}}} }}</pre>
|-
| <small><pre>{{#if: {{{tst}}} | -3- {{{2}}} | '''err''' }}</pre></small>
| {{#if: {{{tst}}} | -3- {{{2}}} | '''err''' }}
| <pre>{{ifdef | {{{tst}}} | -3- {{{2}}} | *** }}</pre>
|-
| <small><pre>{{#if: {{{tst}}} | -4- {{{2}}} }}</pre></small>
| {{#if: {{{tst}}} | -4- {{{2}}} }}
| <pre>{{ifdef | {{{tst}}} | -4- {{{2}}} }}</pre>
|}{{-}}
 
Line 323 ⟶ 282:
| <small><pre>{{#if: {{ns:0}} |n/a| -1- {{{2}}} }}</pre></small>
| {{#if: {{ns:0}} |n/a| -1- {{{2}}} }}
| <pre>{{ifndef |{{ns:0}}| -1- {{{2}}} }}</pre>
|-
| <small><pre>{{#if: {{ns:0}} |n/a| -2- {{{2|default}}} }}</pre></small>
| {{#if: {{ns:0}} |n/a| -2- {{{2|default}}} }}
| <pre>{{ifndef |{{ns:0}}| -2- {{{2|default}}} }}</pre>
|-
| <small><pre>{{#if: {{ns:0}} |n/a| -3- {{{1}}} }}</pre></small>
| {{#if: {{ns:0}} |n/a| -3- {{{1}}} }}
| <pre>{{ifndef |{{ns:0}}| -3- {{{1}}} }}</pre>
|-
| <small><pre>{{#if: {{ns:0}} |n/a| -4- {{{3}}} }}</pre></small>
| {{#if: {{ns:0}} |n/a| -4- {{{3}}} }}
| <pre>{{ifndef |{{ns:0}}| -4- {{{3}}} }}</pre>
|}
 
Line 351 ⟶ 310:
| style="border:1px solid #a3bfb1; background:#f5fffa;"|{{{Date of Retirement}}} | }}</pre>
 
The above shows:<pre>
{{#if: {{{Date of Retirement|}}}|{{{
! colspan="3" style="border:1px solid #a3bfb1; background:#cef2e0;" | Date of Set [[Retirement]] :
| style="border:1px solid #a3bfb1; background:#f5fffa;"|{{{Date of Retirement}}} | }}</pre>
 
But that has the "|" for wiki tables, so I make them into the <pre><td><tr><th></pre> ones.
Line 364 ⟶ 323:
That shows this:
{{#if: {{{Date of Retirement|}}}|{{{
<table><th colspan="3" style="border:1px solid #a3bfb1; background:#cef2e0;"> Date of Set [[Retirement]] :</th>
<td style="border:1px solid #a3bfb1; background:#f5fffa;">{{{Date of Retirement}}}</td></table> | }}
 
Could anyone help me with this?
Line 383 ⟶ 342:
{{!}} style="border:1px solid #a3bfb1; background:#f5fffa;"{{!}}{{{Date of Retirement|Date}}}
{{!}}}| }}
<!-- Template:Unsigned --><span class="autosigned" style="font-size:85%;">—&nbsp;Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[User:CBDunkerson|CBDunkerson]] ([[User talk:CBDunkerson#top|talk]] • [[Special:Contributions/CBDunkerson|contribs]]) 6:52, 3 September 2006 (UTC)</span>
 
== Logical and/or question ==
Line 439 ⟶ 399:
::but now with or without the model {{m|!}}, it shows "<nowiki>style="background:#999999" |}} | {{{1}}}</nowiki>" in my cell. Do you have an idea how to fix it ? --[[User:Moutonjr|Moutonjr]] ([[User talk:Moutonjr|talk]]) 12:13, 30 April 2013 (UTC)
:::Which page is this on? I would like to examine it directly, but I don't see anything relevant in either [[Special:Contributions/Moutonjr]] or [[:fr:Spécial:Contributions/Moutonjr]]. --[[User:Redrose64|<span style="color:#a80000; background:#ffeeee; text-decoration:inherit">Red</span>rose64]] ([[User talk:Redrose64|talk]]) 12:57, 30 April 2013 (UTC)
:::: It is in a local Wikimedia, but my version seems outdated according to [[pl:Wikipedysta:Matma_Rex|MatmaRex]] on IRC, my version is outdated because it works for Wikipedia (1.22) but not in my 1.16. Sorry for the inconvenience... <!-- Template:Unsigned --><span class="autosigned" style="font-size:85%;">—&nbsp;Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[User:Moutonjr|Moutonjr]] ([[User talk:Moutonjr#top|talk]] • [[Special:Contributions/Moutonjr|contribs]]) 13:23, 30 April 2013 (UTC)</span>
 
==the problem of hiding rows in tables with background color==
I use #if in a template to hide rows on some conditions. all works fine except the background color.
I'd like to post the template's sample codes below:
<pre>
{|style="background-color:red;"
!<center>会议</center>
!<center>时间</center>
!<center>地点</center>
!<center>重要讲话</center>
!<center>关键词</center>
|-
|{{#if:{{{2014t|}}}|<center>2014年</center>
{{!}}{{{2014t}}}
{{!}}{{{2014p}}}
{{!}}[[{{{2014s}}}]]
{{!}}{{#if:{{{2014k|}}}|{{{2014k}}}|}}
|}}
|-
|{{#if:{{{2013t|}}}|<center>2013年</center>
{{!}}{{{2013t}}}
{{!}}{{{2013p}}}
{{!}}[[{{{2013s}}}]]
{{!}}{{#if:{{{2013k|}}}|{{{2013k}}}|}}
|}}
|-
|{{#if:{{{2012t|}}}|<center>2012年</center>
{{!}}{{{2012t}}}
{{!}}{{{2012p}}}
{{!}}[[{{{2012s}}}]]
{{!}}{{#if:{{{2012k|}}}|{{{2012k}}}|}}
|}}
|-
|{{#if:{{{2011t|}}}|<center>2011年</center>
{{!}}{{{2011t}}}
{{!}}{{{2011p}}}
{{!}}[[{{{2011s}}}]]
{{!}}{{#if:{{{2011k|}}}|{{{2011k}}}|}}
|}}
|}
</pre>
the background color seems strange at the top and the bottom of the table. anyone can help? thanks.
[[User:Ywanght|Ywanght]] ([[User talk:Ywanght|talk]]) 14:49, 4 March 2014 (UTC)
 
== Looking up a cell within a table ==
{{help me-helped}}
Is there a way of writing a code to search a table for a value, and then use an if statement on it. For example:
{| class="wikitable" name="table"
| p
| q
|-
| r
| s
|}
If I wanted to look up if cell A1 contained 'p', could I do it?--<span style="background:#FF0;font-family:Rockwell Extra Bold">[[User:Launchballer|<u style="color:#00F">Laun</u>]][[User talk:Launchballer|<u style="color:#00F">chba</u>]][[Special:Contribs/Launchballer|<u style="color:#00F">ller</u>]]</span> 16:40, 15 March 2018 (UTC)
:{{u|Launchballer}}, what are you planning on doing if a cell contained "p"? Because if you were just curious ''if'' it contained a "p", then you would use an <code>#ifeq:</code> call. [[User:Primefac|Primefac]] ([[User talk:Primefac|talk]]) 22:06, 15 March 2018 (UTC)
::{{u|Primefac}} Do you know anything about [[Countdown (game show)|Countdown]]? I want to count back 64 episodes from the most recently broadcast episode. It's for the seed table at [http://wiki.apterous.org/Series_78], I want to subtract the most recently broadcast episode from the first quarter final. With less than 64 episodes to be broadcast, the person at the top of the leaderboard is guaranteed a spot there.--<span style="background:#FF0;font-family:Rockwell Extra Bold">[[User:Launchballer|<u style="color:#00F">Laun</u>]][[User talk:Launchballer|<u style="color:#00F">chba</u>]][[Special:Contribs/Launchballer|<u style="color:#00F">ller</u>]]</span> 22:16, 15 March 2018 (UTC)
:::Could you give an example, like, what you want it to look like before and after the "65th" entry is added? Doesn't have to be a full table, just gives me some sort of indication what you're specifically looking for. [[User:Primefac|Primefac]] ([[User talk:Primefac|talk]]) 22:20, 15 March 2018 (UTC)
::::Now I think about it, I don't think you need to read values from elsewhere in a table. I'm muddling up parameters and rows.
{| class="wikitable" name="table"
| p
| <nowiki>{{#if:{{#expr:<first quarterfinal/> - <most recently broadcast episode/>}} < 64|'''seed 1'''|seed 1}}</nowiki>
|}
::::I think I can do that on my own.--<span style="background:#FF0;font-family:Rockwell Extra Bold">[[User:Launchballer|<u style="color:#00F">Laun</u>]][[User talk:Launchballer|<u style="color:#00F">chba</u>]][[Special:Contribs/Launchballer|<u style="color:#00F">ller</u>]]</span> 22:34, 15 March 2018 (UTC)
::::{{u|Primefac}} Ah! How do you go about finding the first cell to contain exactly " - "?--<span style="background:#FF0;font-family:Rockwell Extra Bold">[[User:Launchballer|<u style="color:#00F">Laun</u>]][[User talk:Launchballer|<u style="color:#00F">chba</u>]][[Special:Contribs/Launchballer|<u style="color:#00F">ller</u>]]</span> 22:38, 15 March 2018 (UTC)
:::::An <code>#ifeq:<param>|-|</code> call. [[User:Primefac|Primefac]] ([[User talk:Primefac|talk]]) 22:55, 15 March 2018 (UTC)
 
== Conditional number of lines/raw? ==
 
How to make a table with a conditional number of lines or raws?
 
For instance, if the variable number_of_lines is 3, it generates 3 lines? <!-- Template:Unsigned IP --><small class="autosigned">—&nbsp;Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/87.91.51.235|87.91.51.235]] ([[User talk:87.91.51.235#top|talk]]) 12:15, 17 November 2019 (UTC)</small> <!--Autosigned by SineBot-->
:You would need to use a template to do this; the default "table-creation" setup wouldn't work like that. [[User:Primefac|Primefac]] ([[User talk:Primefac|talk]]) 13:09, 17 November 2019 (UTC)
 
== Conditional columns ==
 
The intro sentence mentions conditional columns, but then they are never mentioned again. I have a table with conditional columns, but I don't know if there's any demand for this elsewhere. If there's interest, ping me and I'll look into seeing whether it's worth generalizing a one-off into something more usable, or just documenting what I have. [[User:Mathglot|Mathglot]] ([[User talk:Mathglot|talk]]) 11:26, 5 February 2025 (UTC)