Help talk:Conditional tables

MUST use HTML
Circeus 14:07, 17 March 2006 (UTC)
 * Actually, you MUST use HTML to hide rows with Qif, because otherwise the pipes of the table syntax conflicts with those of the template syntax.
 * You'll want to reference the Boolean templates too
 * For some reason I thought it might work with the table syntax if you used sub templates, like this–


 * Template:Foo


 * Template:Foo/Bar

|- ! Foo


 * 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. —Locke Cole • t • c 16:14, 17 March 2006 (UTC)


 * I tried to understand boolexists because I don't like Qif and want a simpler, 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. Omniplex 14:08, 19 March 2006 (UTC)


 * The point MUST use HTML turned out to be wrong, see below and !, it's more like MAY use XHTML. Omniplex 11:20, 21 March 2006 (UTC)

New attempt

 * Note: most of the templates referred to in this discussion have since been repurposed for other tasks. Happy]]‑melon 13:17, 26 September 2008 (UTC)

Mixing XHTML with Wiki table syntax is a layer violation, and some uses in for the shortcut are incorrect, missing &lt;tr&gt; and similar issues, in other words FUBAR. But it should be possible to get it to work somehow with Wiki syntax.

Apparently that works, we need a shorter name for the template returning a vertical bar... ;-) Omniplex 13:57, 19 March 2006 (UTC)
 * Hm, we could always use Lowercase and TD. Then the code turns into–


 * Which ain't pretty, but might be better than pure (X)HTML. Regarding the header templates, I only looked at one I admit, but it looked like it was just defining another column in the already existing row (so no need for ). The one thing I saw that did kind of bug me was the nesting of   within  . —Locke Cole • t • c 21:01, 19 March 2006 (UTC)


 * Yes, at the time when you inserted it I had no clue what it's supposed to do, i.e. avoid the reserved "|" within Qif. A dummy template with output "|" might be cleaner. We don't need &lt;th&gt;, "!" is okay. Maybe a second dummy template for "||", but actually I'd say one is bad enough, and "||" is never required. Omniplex 21:55, 19 March 2006 (UTC)


 * I've trimmed my old comment with &lt;s&gt; reflecting Locke's comment and replaced tl2 by tlp in the sample table. Omniplex 10:01, 21 March 2006 (UTC)


 * Well, if you just want to make a template for the vertical bar, I note that B and V are available. (B for bar, V for vertical-bar?). I know AzaToth prefers (and I somewhat agree) using straight (X)HTML for table syntax (in other words, no wiki-markup at all). I don't know that using a sub-template to get the bar would be any better or worse from a code-readability point of view though... I'm leaning towards worse, but I need to look at it more. HTML table syntax isn't that complicated though (really just five tags that people would need to know; TABLE, TR, TD, TH, and CAPTION). And the mix of HTML and qif can be neatly separated.
 * 2008 update: B is no longer available. —  SMcCandlish  &#91;talk&#93; &#91;cont&#93; ‹(-¿-)› 15:30, 30 August 2008 (UTC)
 * By all means though you should edit this in as another alternative if you think it'd be more readable. =) —Locke Cole • t • c 22:10, 19 March 2006 (UTC)


 * Such a solution risk making styling these cells hell. What's so bad with XHTML in there?. Circeus 22:07, 20 March 2006 (UTC)


 * If what you need is say
 * you could use
 * As straight forward as possible. 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 Qif, only the vertical bar has to be escaped from the parameter default mechanism. Normally &amp;#124; is good enough, but within a table it needs a template. I've created ! for this purpose. Omniplex 22:20, 20 March 2006 (UTC)

Ifdef
Not really necessary to invent a third method, but I'm interested to get some ideas about its fragility: The code above is in qif_example_2/b. The table below demonstrates the effect when it's used:

So far apparently fine, but it didn't work with at least one of the Wikipedia header templates.

The Ifdef code is straight from Meta. It's the Qif version without else replacing the remaining named parameters test and then by positional parameters 1 and 2 resp.

Please don't try to fix it, I want it as simple as is, but it makes me nervous that I don't understand why it's so fragile. --&#160;Omniplex 16:17, 27 March 2006 (UTC)

Answered by Paddu in Ifdef, executive summary: Use if then contains any " = ". Minimalism has its drawbacks. --&#160;Omniplex 22:15, 17 April 2006 (UTC)

TfD nomination of Template:Ifdef
Template:Ifdef has been nominated for deletion. You are invited to comment on the discussion at the template's entry on the Templates for Deletion page. Thank you. --&#160;Omniplex 15:15, 18 April 2006 (UTC)

Direct ifdef approach
After some drawbacks with #if: and Ifdef have been identified (and for the latter documented) it's time to check out the m:Help:Parameter default mechanism directly with no if-construct at all as in the upgraded The code above is in qif_example_2b. The table below demonstrates the effect when it's used:

An expected minor difference in the first line, otherwise it works. This method is now documented in Advanced_templates on Meta.

There are apparently some drawbacks with substituting templates containing many ifdef-constructs, it replaces pointless code for ifndef cases. --&#160;Omniplex 01:58, 22 April 2006 (UTC)
 * Putting the basic logic behind 'qif' and 'switch' directly into the final template like this has been called 'Weeble code' or the 'blank parameter trick' in the past. Examples previously in widespread use can be seen here and here. The general drawback of the method is the need to deliberately set a parameter value to 'blank' (as opposed to unset) so that it may act as a switch. Users calling the template will often assume that a parameter set blank is the same as an unset parameter and exclude it... thereby deactivating the conditional feature. This isn't a problem if the blank parameter is set by a template which then calls another template, but then the anti 'meta-template' jihadists take up arms. Ergo... ParserFunctions was developed. --CBDunkerson 08:08, 22 April 2006 (UTC)

New twist in the 5678 saga, it breaks after substitutions. If I'd want to do something with and need no "else" code, then I'd use the old mechanism, it's harder to destroy it. --&#160;Omniplex 05:34, 16 May 2006 (UTC)

Interwiki link to vi:

 * Note to admin handling this: Template talk:! redirects here (which is fine), hence why the request for modification is here and not there.

Please add an interwiki link at Template:! to the Vietnamese version of that template:

vi:Tiêu bản:!

Thanks.

– Minh Nguyễn (talk, contribs) 19:50, 8 April 2006 (UTC)


 * Done. --CBDunkerson 20:36, 8 April 2006 (UTC)


 * My bad, I didn't expect a protection when I redirected it. --&#160;Omniplex 20:50, 8 April 2006 (UTC)

ParserFunctions
Ok, so we have built-in conditionals (per header) on a trial basis. Unfortunately, they work nearly the same as QIF except for a few issues;


 * 1) The '#if:' feature does not use 'parameter names'. So, '|test= |then= |else= ' becomes just '| | | '. Overall I think the shorter format is better - though it requires that a user know the order of the parameters rather than being able to set them in any order.
 * 2) For 'QIF' a '|test=0' condition resolved to 'test exists' and was therefor 'TRUE'. For '#if:' a condition of '0' resolves to 'FALSE'. Again, I think this is an improvement overall. It may change the behaviour of a few templates, but it simplifies the use of conditions based on mathematical and boolean logic.
 * 3) Finally, #if: seems to have a problem with line breaks that can be somewhat confusing;

This works as expected;
 * - valign=top

This does not;
 * - valign=top

Essentially, #if: ignores the line break after the condition and the second scenario above resolves as;
 * - valign=top | Parameter:
 * 

Obviously that isn't proper table markup and thus the 'Parameter:' just is not displayed. This is easy enough to resolve by placing the '{{#if:' on a new line, but it is an additional limitation compared to 'QIF'.

Other than those issues I think #if: and QIF are essentially identical in function. You can use HTML tags (i.e., ,  ) or the {{!}} template trick - provided you keep the line-break issue in mind, but not direct '|' table markup. It accepts '|' in wiki-links like QIF. Less than we might have hoped for, but I think a viable replacement... and the other new features (expr: & rand:) are wonderful. The #ifeq is similar to the 'booleq' template, but I'll have to do more testing - I suspect it has the same sort of minor quirks as '#if:' vs 'qif'. --CBDunkerson 11:38, 13 April 2006 (UTC)
 * Something tells me the bit with #if treating "0" as false will bite us more than help us. See my suggestion on ParserFunctions for a #ifexpr. If that were implemented, I think #if should be modified to be a simple empty/non-empty test. Or would there still be a good reason for the true/false test? —Locke Cole • t • c 12:10, 13 April 2006 (UTC)


 * Stuff written by me now documented in 5569 removed here, the &lt;pre&gt; bugs are unrelated to {{Tlx|Qif}} and #if; oddities. --&#160;Omniplex 22:23, 17 April 2006 (UTC)

Updated instructions
I've updated the instructions to use  instead of qif. The only loose-end that remains is updating Infobox (which is still referenced in these docs) and deciding upon a new name for this page. Originally I planned on moving this to If conditionals, but maybe ParserFunctions conditionals would be more appropriate (and would allow for later expansion to include examples using,   and so forth)? Or perhaps a more generic name, like Template conditionals? Comments welcome, also, if anyone notices anything I missed in the article, please correct. =) —Locke Cole • t • c 05:47, 17 April 2006 (UTC)


 * I've added a caveat about " = " and positional parameters. Where works (no else needed) it's unnecessary to replace it by #if: (and v.v.). Renaming  is tricky, what about all its links and the shortcut? --&#160;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. —Locke Cole • t • c 16:27, 18 April 2006 (UTC)
 * Double redirects are shown, but what about dozens of w:Wikipedia:Qif& on Meta? Maybe I even used w:WP:QIF or similar there. --&#160;Omniplex 00:47, 22 April 2006 (UTC)
 * As WP:QIF would be changed to point to the new name (and Qif conditionals would also point to the new name) it shouldn't matter. —Locke Cole • t • c 01:00, 22 April 2006 (UTC)

#if: 5678 watch
A condensed variant of the table posted on Talk:ParserFunctions, see also 5678. Test cases for the "else" anomaly clobbering the second parameter and comparisons with ifdef and ifndef added, subst test case removed (known to fail with ifndef or qif). The problem is fixed if 2nd and 3rd coloumn show roughly the same result.

#if: else {&#123;{2}&#125;} anomaly
--&#160;Omniplex 00:28, 28 April 2006 (UTC)
 * You might want to look at http://test.wikipedia.org/wiki/ParserFunctions and see if the examples there cover the cases you're concerned with. —Locke Cole • t • c 01:13, 28 April 2006 (UTC)


 * The "Special:Captcha" inline PNGs don't work for me, I only have a Meta-account because Pathoschild created it for me. The backlink at 5678 should do it. --&#160;Omniplex 00:38, 1 May 2006 (UTC)

Use with table formating
I've looked for a way to include formating into a table using #if: I've tryed HTML Table Coding for adding a background colour/image, and i just get the code showing up. And Since i can't use the "|" I can't get Table to have colour or anything else like that.

{{#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}}} | }}

The above shows: {{#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}}} | }}

But that has the "|" for wiki tables, so I make them into the    ones.

{{#if: {{{Date of Retirement|}}}|{{{  Date of Set Retirement : {{{Date of Retirement}}} | }}

That shows this: {{#if: {{{Date of Retirement|}}}|{{{ | }}

Could anyone help me with this? I should also mention, I am New at this.
 * The standard way around this problem is to use {{!}}... this is a template which contains nothing but a '|' character. It is left as a template for the evaluation of the #if:, but then after the conditional logic the | is transcluded in and used normally for table logic. There were a few other issues with the examples (extraneous brackets, no table open/close, blank parameter and thus evaluating to nothing, et cetera) which I adjusted as follows;

{{#if: {{{Date of Retirement|Date}}}| {{{!}} ! colspan="3" style="border:1px solid #a3bfb1; background:#cef2e0;" {{!}} Date of Set Retirement : {{!}} style="border:1px solid #a3bfb1; background:#f5fffa;"{{!}}{{{Date of Retirement|Date}}} {{!}}}| }}

Shows: {{#if: {{{Date of Retirement|Date}}}| {{{!}} ! colspan="3" style="border:1px solid #a3bfb1; background:#cef2e0;" {{!}} Date of Set Retirement : {{!}} style="border:1px solid #a3bfb1; background:#f5fffa;"{{!}}{{{Date of Retirement|Date}}} {{!}}}| }} — Preceding unsigned comment added by CBDunkerson (talk • contribs) 6:52, 3 September 2006 (UTC)

Logical and/or question
I have a question I'm hoping someone can help with. Is there any way to do boolean and/or with parameters and #if, short of using nested if blocks? For instance, Any help would be much appreciated. — George Saliba[ talk ] 20:40, 5 December 2006 (UTC)


 * Nevermind, I figured it out. For or at least you just do {{#if: {{{param1|}}}{{{param2|}}} |then case... — George Saliba[ talk ] 10:50, 6 December 2006 (UTC)


 * Has anyone figured out how to do a logical AND? Please mention it on my talk page if you do. Hypertall (talk) 21:59, 6 May 2012 (UTC)
 * It's more complicated, but possible:
 * -- Red rose64 (talk) 23:05, 6 May 2012 (UTC)
 * -- Red rose64 (talk) 23:05, 6 May 2012 (UTC)

Help with conditionals with specific variables and if/then
I am working on a template User:Andrew c/New Testament manuscripts. Instead of forcing the user to format numbers in a specific way, I would like the template to automatically code the numbers based on what class they imput. For example, if the class is set to "papyrus" the number function gets put into a superscript. If the class is set to "Uncial", the number gets bolded. If the class is a lectionary, the number gets italicized. You can look through the history to see the sort of things I have tried out. My problem is I don't know how to get the if to recognize a user inputted variable, and I do not know how to combine multiple conditionals. Any help would be greatly appreciated. Thanks.-Andrew c 18:30, 11 May 2007 (UTC)

Requested move
Conditional display of table rows makes much more sense, since... er, that's what it's about. (Still not sure what a "qif" is when it's at home...) -- 217.42.77.246 12:02, 4 September 2007 (UTC)


 * This page is mostly kept for historical purposes since 'qif' has been deprecated and replaced by ParserFunctions. Thus, a move to some other name would not make sense as people would only be looking at it based on it's past history of use under this name. Also, the conditional logic introduced by qif could be used for all kinds of conditions... not just conditional display of rows. As to the name itself, I believe it was short-hand for 'quicker if'... the original 'Template:If' conditional method having been slightly more computationally involved than qif. --CBD 13:07, 4 September 2007 (UTC)


 * Can it at least be marked as historical, then, so that people coming across it for the first time don't start wondering what on earth it is? -- 217.42.77.246 17:30, 4 September 2007 (UTC)


 * I went to do that... and found that the page has been completely rewritten. It now covers the use of the #if parserFunction for table logic (both columns and rows) rather than Qif at all. Oops, sorry about that. As such I agree that a name change makes sense. How about something like 'Wikipedia:Conditional tables'? --CBD 23:33, 5 September 2007 (UTC)


 * Sounds OK to me... -- 86.133.138.146 14:47, 7 September 2007 (UTC)

Please help with Rows in tables
I'm trying to follow the correct usage plan A and when I include and commands in my templates (to construct tables, rows and cells) the output I receive is and rather than it interpreting as HTML tags. What am I doing wrong? Please help. 118.209.133.131 (talk) 04:07, 4 August 2012 (UTC)
 * OK I think I have worked it out. If I use wiki text to create the table and HTML tags to create cells it doesn't work. But if I go 100% HTML tags then it works. This is what I'm doing now and getting all my work done a lot quicker now. Previously I had problems where extra paragraphs would appear and if I pushed the wiki text on the same line then it would do different things. Wiki text appears somewhat useless for tables. 118.209.133.131 (talk) 06:52, 4 August 2012 (UTC)
 * You don't actually say which page this is on, and your contributions don't list any edits to pages other than this one. If you give the article name, we may be able to fix up any tables in that article. -- Red rose64 (talk) 16:28, 4 August 2012 (UTC)

Using ifdef in a template
Hello, I'm stuck in front of a problem I can't understand. I try to change the background of a table cell conditionnally with ifdef using styles. That is to say, in my template which looks like,  if my Value isn't defined  , I want the background to be grey.

To do so, I implemented this code :

| align="center" |

The code of my template ifdef seems actually weird, The source code is as follows :

Obviously, my code doesn't run, it prints what I want in the celle but doesn't format it.

Does anyone have an idea how to achieve what I want ? Or some clues? Thank you very much! Moutonjr (talk) 09:46, 30 April 2013 (UTC)
 * There is no template named, nor one named . In the case of ifdef, are you perhaps thinking of one of the parser functions? -- Red rose64 (talk) 10:02, 30 April 2013 (UTC)
 * Actually, I named my own model like this for the example :). I try to use the Parser Function #if but now I've got another problem... I tried to type :
 * | align="center" |
 * but now with or without the model, it shows " style="background:#999999" |}} | " in my cell. Do you have an idea how to fix it ? --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. -- Red rose64 (talk) 12:57, 30 April 2013 (UTC)
 * It is in a local Wikimedia, but my version seems outdated according to MatmaRex on IRC, my version is outdated because it works for Wikipedia (1.22) but not in my 1.16. Sorry for the inconvenience... — Preceding unsigned comment added by Moutonjr (talk • contribs) 13:23, 30 April 2013 (UTC)

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: the background color seems strange at the top and the bottom of the table. anyone can help? thanks. Ywanght (talk) 14:49, 4 March 2014 (UTC)

Looking up a cell within a table
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: If I wanted to look up if cell A1 contained 'p', could I do it?-- Laun chba ller 16:40, 15 March 2018 (UTC)
 * , 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  call. Primefac (talk) 22:06, 15 March 2018 (UTC)
 * Do you know anything about Countdown? I want to count back 64 episodes from the most recently broadcast episode. It's for the seed table at, 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.-- Laun chba ller 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. 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.


 * I think I can do that on my own.-- Laun chba ller 22:34, 15 March 2018 (UTC)
 * Ah! How do you go about finding the first cell to contain exactly " -  "?-- <u style="color:#00F">Laun <u style="color:#00F">chba <u style="color:#00F">ller  22:38, 15 March 2018 (UTC)
 * An  call. 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? — Preceding unsigned comment added by 87.91.51.235 (talk) 12:15, 17 November 2019 (UTC)
 * You would need to use a template to do this; the default "table-creation" setup wouldn't work like that. Primefac (talk) 13:09, 17 November 2019 (UTC)