Help talk:Extension:ParserFunctions/2014-2020

replacing #ifexist with #dpl
The behaviour of #ifexist can be reproduced with DPL using the following syntax:
 *  

which is equivalent to:
 *  

DPL has the advantage that it does not create a link between the target page (page title) and the page containing the query. Using #ifexist would cause your page to be listed in Special:WhatLinksHere/page_title.

—Capmo (talk) 06:42, 18 August 2012 (UTC)


 * #ifexist is faster. Avoid calling DPL wherever you can. --Subfader (talk) 13:23, 19 August 2012 (UTC)


 * DPL makes direct queries to the database, what can be faster than this? And there must be a reason for #ifexist to be labeled as an "expensive parser function". The wiki I administer uses DPL extensively for all sorts of things, and we don't feel any perceivable degradation in server performance. Capmo (talk) 21:53, 21 August 2012 (UTC)


 * Initializing DPL on page load takes longer than ParserFunctions. "#ifexist to be labeled as an "expensive parser function"" that's because the DB load gets expensive on calling it X times, but the same counts for calling DPL X times on a page... --Subfader (talk) 11:50, 22 August 2012 (UTC)

If A or B or C (resolved)
I am trying to use the if statement to test for multiple different values.

For example: would display "YES" if any of the three (a,b,c) variables were defined. If, and only if, all 3 were NOT defined, it would display "NO".

I simply cannot get this to work! Any help would be most appreciated.

--Zackmann08 (talk) 01:09, 10 September 2012 (UTC)


 * Try it like this . If one of the parameters has a value it will display YES, only when non of the parameters has a value it will display NO. In this way you can make any combination you want and make it as complicated as you want. --Jongfeli (talk) 09:03, 10 September 2012 (UTC)


 * The issue is that I am attempting to use this to do something much more complex than just displaying "YES" and "NO". I am using it to create a rather large table. Is there no way to do "If A or B or C"? --Zackmann08 (talk) 13:50, 10 September 2012 (UTC)


 * If I understand you correctly you would like to fill a (calculated) column in a table and the value depends on other values in the same row? I tried this in combination with Extension:External Data but  does not work because it probably always gets a value back from the Query. It does not matter if there is a database NULL in the table or an empty string. Just to see if it can work I tried   (see example below) but it only works on the first row it displays, if in the first row a = 1 it will display Yes and it will repeat the result on the rest of the rows even if a is not 1.

{| class = "wikitable" ! Column 1 ! Column 2 ! Column 3 ! Test
 * Maybe I am doing something wrong but it seems that in combination with External Data the ParserFunctions does not handle each row individually. --Jongfeli (talk) 15:19, 10 September 2012 (UTC)


 * This is part of an infobox. I am trying to copy the technique used on wikipedia (For example: http://en.wikipedia.org/w/index.php?title=Template:Infobox_weapon&action=edit)
 * In the example below, the heading for the "Service History" only displays if "service", "used_by" or "wars" is defined. For some reason, this exact syntax is not working for me.








 * --Zackmann08 (talk) 15:47, 10 September 2012 (UTC)


 * So its now working. Not sure what i was doing wrong... Oh well! --Zackmann08 (talk) 16:26, 10 September 2012 (UTC)

If number check (resolved)
I am attempting to write an error checking function that checks to see whether a user has supplied either a year (####) or the word "Present". (This is for an infobox for a vehicle. I want to display the production years.) I am 99% of the way there with the following:

The issue that I am having is that if a valid date is supplied, then the expression evaluates and is displayed. Is there an easy way to suppress that expression? I seem to remember seeing a "span display=none" type thing somewhere...

Any advice will be greatly appreciated.

--Zackmann08 (talk) 14:35, 19 September 2012 (UTC)


 * I love solving my own problems. :-) was my solution. --Zackmann08 (talk) 14:40, 19 September 2012 (UTC)


 * I also had a similar question because the parser functions give script errors in some cases. I had do this. --Rical (talk) 22:50, 19 September 2012 (UTC)

How to use tag function within parser function?
I'm trying to build an if-clause that automatically inserts == References ==  character or possibly a tag inside a function where tags aren't allowed. However, even when I remove all instances of the  character from the template (by eliminating the comments, the   tags, and the   tags), the error message persists.

Here is the text of the template:

[removed]

Any idea what the problem is and/or how I can correct it? Thanks! ~ Michael Chidester (Contact) 15:07, 22 March 2013 (UTC)

Solution
Ultimately I determined that this was a DPL conflict, possibly due to the  function refusing to parse the standard output format of DPL. To help anyone having this problem in the future, here is my modified code, changing out the deprecated string functions for their replacements and modifying the DPL output to produce a regular string rather than a link:

The next document number is 

Cheers. ~ Michael Chidester (Contact) 15:40, 26 March 2013 (UTC)

See also Scribunto ?
Now, we have modules in scribunto/Lua and the syntax to call them is " {{#invoke| ". Then users will try to search them here and we could add Extension:Scribunto to "See also" paragraph ? --Rical (talk) 18:13, 11 May 2013 (UTC)
 * I think you should create a section Extension:Scribunto/Lua reference manual on the extension page, since that should bring this section to the top of the search results when people search "invoke". --Theaitetos (talk) 22:11, 12 May 2013 (UTC)

How can we do a sum ?
Hello ! Is there a function to do the sum of A+B+C+D+E ? Historymating (talk) 11:42, 8 June 2013 (UTC)


 * expr can calculate sums. But it's not possible for any function to process things, that are not in the input area of the function itself. --Theaitetos (talk) 13:58, 28 June 2013 (UTC)

Unwanted whitespace in article from #switch
I'm using a template whose entirety is just a switch statement to transclude one of two possible subtemplates. However, ParserFunctions seems to be adding an extra line of whitespace before the result of the switch statement when I use it this way. Is there a way to remove this whitespace?--Idran (talk) 01:46, 28 June 2013 (UTC)


 * Hello Idran. You should first check if the template adds the white space (line break). If you want to be strict on what gets transcluded via the template make sure you put everything that needs to be transcluded between  tags. Below an example.

Any Template documentation

 * Bla bla 1
 * Bla bla 2
 * Bla bla 3


 * If you don't do that you could easily transclude a line break to a page. --Jongfeli (talk) 08:34, 28 June 2013 (UTC)


 * I disagree with Jongfeli. en:Help:Transclusion has an informative section on how transclusion and the various include tags work.  Idran if you could post the markup from your template here, I would be happy to help you make it work as you expect.  I'm thinking the #switch might not be needed if there are only two outcomes and maybe an #ifeq would work better. Technical 13 (talk) 12:13, 28 June 2013 (UTC)


 * Actually while I was copying the code of the templates here, I noticed exactly what the problem was; I had an includeonly section in the subtemplates that I hadn't realized was adding an unwanted linebreak, and I didn't notice it because I was focusing my attention on the template itself. Apologies for the unnecessary responses!--66.254.228.224 19:26, 28 June 2013 (UTC)


 * Whoops, didn't notice I wasn't logged in; that was me above.--Idran (talk) 19:59, 28 June 2013 (UTC)

Hebrew calendar (Jewish calendar) date as date/time object
Is there a way to enter a Hebrew calendar date as a date/time object in the #time: function? In other words, I know how to get a Hebrew calendar date out by entering a Gregorian date/time object in the function. Can I do it the other way around? Thanks. StevenJ81 (talk) 01:34, 24 July 2013 (UTC)

HTML and Parser functions
I have tried to use Parser functions with HTML(More accurately CSS), but there is some conflict made by the ">" operator. What can I do in order to solve the problem? Thanks. 219.78.217.178 22:40, 9 August 2013 (UTC)
 * Without you showing us the code in question that you are getting errors for, the first suggestion I may offer is to use &amp;lt; and &amp;gt; to achieve &lt; and &gt; respectively. Technical 13 (talk) 23:37, 9 August 2013 (UTC)


 * For example, using a style tag...
 *  180 | 180 | }}$}}deg);'>

The > makes the tag closed and caused errors, so what should I do? 219.78.217.178 10:00, 14 August 2013 (UTC)


 * First, there is a significant typo when closing the parameter degree with  instead of  :
 * If that doesn't fix the problem, try turning the ifexpr around: . --Theaitetos (talk) 18:29, 19 August 2013 (UTC)

Bug in time code?
"Feb" is getting reported as 3 for format letter "n" (see below) Esjs (talk) 16:03, 30 August 2013 (UTC)
 * Sorry for posting here. I've also posted this at Extension talk:ParserFunctions Esjs (talk) 16:18, 30 August 2013 (UTC)
 * Technical 13 (talk) fixed table width by splitting in half at 18:13, 30 August 2013 (UTC)

handling of incomplete dates
"Full or partial absolute dates can be specified; the function will "fill in" parts of the date that are not specified using the current values:"

I think this is not acceptable behaviour, unless it can be switched on or off. I am parsing incomeplete dates, and if you have a historical Person in a wiki with a birth date "May 1875" than the #time function should return nothing for a day and not the current day!!
 * You have full control over how you format the output of the #time function. If you only want month, year, then   produces  when you pass may 1875.  If you want to make it more complicated, then try playing with:
 * day month year
 * 5 month year
 * 5 5 year
 * 5 month 1875
 * 5 5 1875
 * day 5 1875
 * day month 1875
 * day 5 year
 * You can also change the layout so that it looks like any of these:
 * If you want to make it really complex:
 * day month year
 * 5 month year
 * day 5 year
 * day month 1875
 * 5 5 year
 * 5 month 1875
 * day 5 1875
 * 5 5 1875
 * I hope this satisfies your need... Technical 13 (talk) 14:12, 19 September 2013 (UTC)
 * Thank you for these great examples, but it's not quite what I need. I have dates and some of them are incomplete. Say "24 April 1875" or "Mai 1920". If I use  I get "24" which is fine, but with   I recieve "1". But it rather should return an error, because if there is no day present I don't want to get a day... --Krabina (talk) 06:39, 24 September 2013 (UTC)
 * If you want to make it really complex:
 * day month year
 * 5 month year
 * day 5 year
 * day month 1875
 * 5 5 year
 * 5 month 1875
 * day 5 1875
 * 5 5 1875
 * I hope this satisfies your need... Technical 13 (talk) 14:12, 19 September 2013 (UTC)
 * Thank you for these great examples, but it's not quite what I need. I have dates and some of them are incomplete. Say "24 April 1875" or "Mai 1920". If I use  I get "24" which is fine, but with   I recieve "1". But it rather should return an error, because if there is no day present I don't want to get a day... --Krabina (talk) 06:39, 24 September 2013 (UTC)
 * 5 5 year
 * 5 month 1875
 * day 5 1875
 * 5 5 1875
 * I hope this satisfies your need... Technical 13 (talk) 14:12, 19 September 2013 (UTC)
 * Thank you for these great examples, but it's not quite what I need. I have dates and some of them are incomplete. Say "24 April 1875" or "Mai 1920". If I use  I get "24" which is fine, but with   I recieve "1". But it rather should return an error, because if there is no day present I don't want to get a day... --Krabina (talk) 06:39, 24 September 2013 (UTC)
 * 5 5 1875
 * I hope this satisfies your need... Technical 13 (talk) 14:12, 19 September 2013 (UTC)
 * Thank you for these great examples, but it's not quite what I need. I have dates and some of them are incomplete. Say "24 April 1875" or "Mai 1920". If I use  I get "24" which is fine, but with   I recieve "1". But it rather should return an error, because if there is no day present I don't want to get a day... --Krabina (talk) 06:39, 24 September 2013 (UTC)
 * Thank you for these great examples, but it's not quite what I need. I have dates and some of them are incomplete. Say "24 April 1875" or "Mai 1920". If I use  I get "24" which is fine, but with   I recieve "1". But it rather should return an error, because if there is no day present I don't want to get a day... --Krabina (talk) 06:39, 24 September 2013 (UTC)


 * The problem is that  returns the same result as  . Both are 1 but in case of April 2013 it is an assumption. Depending what users are doing with the result things could take a wrong turn on there wiki's. The desired result should be something that can not be a day, like 0 so users can "catch" it. Regards, --Jongfeli (talk) 10:00, 24 September 2013 (UTC)

using #ifexist to check for files in templates
I'm using something like the above in a template to check for files. It works fine, but if files corresponding to $(${PAGENAME}}.png are added after the pages transcluding this template is edited, the files show up in Unused Files list and the File:{{PAGENAME}}.png links show up in Wanted Pages list, not Wanted Files list. Purging any of the relevant pages doesn't fix it. Only editing the pages which have the template transluded updates the link lists. the Is there a way around this bug? - 91.156.198.247 04:56, 8 October 2013 (UTC)

Cleanup number with thousands separator
When calculating with a number like, a number with thousands separator (comma in enwiki) is returned like. Is there a cleanup function, and shouldn't we add that to this helppage? -DePiep (talk) 11:46, 7 November 2013 (UTC)

Undocumented feature of #time
Hello, I was just trying something that I thought might work, and it did, despite it not being listed here. it might be useful to add such a note to the page. (if it is noted, then my apologies, but it wasn't obvious) Which displays the second sunday in march at 10:00. -90.217.231.103 09:34, 16 November 2013 (UTC)


 * This is documented. Go to Help:Extension:ParserFunctions and scroll down until you see "Minutes and seconds" in the table to the right. Allen4names (talk) 15:17, 5 February 2014 (UTC)

help
How can I test if a parameter starts with a parenthesis? I wish to add parentheses to a number template when the uncertainty is input as ±x, but not when it's formatted as (x). So I'd like to test if the first character of the string is a parenthesis, or if the string contains a parenthesis, and only add parentheses when this is false. Kwamikagami (talk) 07:43, 7 February 2014 (UTC)
 * Hello Kwamikagami, you would either need to have Extension:StringFunctions or Extension:Scribunto installed to be able to do such I thing I believe. Technical 13 (talk) 08:08, 7 February 2014 (UTC)


 * Thanks. I'm working on WP, which has them installed, doesn't it?  Kwamikagami (talk) 08:20, 7 February 2014 (UTC)
 * The English Wikipedia has Extension:Scribunto installed. There is also already a string functions module written which you can see on en:Module:String.  What you'll want to use to see if "(" is the first character is   Technical 13 (talk) 10:24, 7 February 2014 (UTC)


 * Thanks! I didn't even know that was there. I've always come here.  But what they have isn't enough for me to follow: If param A begins with / contains (, I want to do X, otherwise Y.  What I have is (for param 2):
 * but it has no effect. Kwamikagami (talk) 11:22, 7 February 2014 (UTC)
 * Happy editing! Technical 13 (talk) 11:55, 7 February 2014 (UTC)
 * I don't understand: It's false whether there's a parenthesis or not.  But someone else found a way of doing this with just {{#if:{{#ifexpr:0{{{2}}}}}|, so I won't need this after all.  (I was trying to do it on my own so someone else wouldn't have to.) Thanks, though.  Kwamikagami (talk) 18:47, 7 February 2014 (UTC)
 * Happy editing! Technical 13 (talk) 11:55, 7 February 2014 (UTC)
 * I don't understand: It's false whether there's a parenthesis or not.  But someone else found a way of doing this with just {{#if:{{#ifexpr:0{{{2}}}}}|, so I won't need this after all.  (I was trying to do it on my own so someone else wouldn't have to.) Thanks, though.  Kwamikagami (talk) 18:47, 7 February 2014 (UTC)
 * Happy editing! Technical 13 (talk) 11:55, 7 February 2014 (UTC)
 * I don't understand: It's false whether there's a parenthesis or not.  But someone else found a way of doing this with just {{#if:{{#ifexpr:0{{{2}}}}}|, so I won't need this after all.  (I was trying to do it on my own so someone else wouldn't have to.) Thanks, though.  Kwamikagami (talk) 18:47, 7 February 2014 (UTC)
 * I don't understand: It's false whether there's a parenthesis or not.  But someone else found a way of doing this with just {{#if:{{#ifexpr:0{{{2}}}}}|, so I won't need this after all.  (I was trying to do it on my own so someone else wouldn't have to.) Thanks, though.  Kwamikagami (talk) 18:47, 7 February 2014 (UTC)


 * Yeah, it wasn't earlier. Using the English Wikipedia version of the module, it works, however, using that version broke multiple templates on this wiki that will need to be updated before I can update the module.  You'll have to take my word for it that it will work properly on the English Wikipedia. :/ Technical 13 (talk) 21:48, 7 February 2014 (UTC)

tags
how can i add tags to my template so if i have only 1 tag it will not display empty spaces or tag icons without words? (sometimes i have a few tags)

Unwanted line breaks in if statements
Hi.

I have the following in a table:

At the end of each #if block I get a    in the HTML leading to ugly line breaks if one or more if the fields is hidden.

Any ideas?

Thanks.

How to insert Vertical Bar (|) in if statement
For example, if I want to insert || if exists, I should use. However, the program will think the Vertical Bars are part of the statement. --Kuwaity26 (talk) 18:35, 18 June 2014 (UTC)


 * See Help:Template#A parameter value containing a pipe character. --Theaitetos (talk) 18:48, 18 June 2014 (UTC)

Maybe an error in documentation
I don't know if I misunderstood what is written, but I really don't understand what means the sentence: "For preventing trimming then- and else-parts, see m:Template:If. Some people use also &lt;nowiki&gt; &lt;/nowiki&gt; instead of spaces.". AFAIK, the &lt;nowiki&gt; can not be used to prevent the trimming of spaces. Can someone clarify this part for me? --Diego Queiroz (talk) 17:36, 4 October 2014 (UTC)
 * Actually it does work:
 * results in
 * Without the nowiki-Tags, you would get:
 * The nowiki-Tags prevent that the whitespace at the beginning and end of the 3rd (then) and 4th (else) parameter gets trimmed. Or you can build a template like the one over at Metawiki: m:template:if. --Theaitetos (talk) 18:40, 4 October 2014 (UTC)
 * Thanks for the answer. Now I got it, but in the current text, it is not clear that it only works for a single space.  My interpretation was that it allows me to use multiple spaces, which is not true.  In addition, it would be good to suggest the use of &amp;nbsp; (or even &amp;#32; for a breakable space), like these:
 * → I thinkDescartes. (non-breakable, allow multiple spaces)
 * → I thinkDescartes. (breakable, does not allow multiple spaces)
 * What do you think? --Diego Queiroz (talk) 21:01, 4 October 2014 (UTC)
 * → I thinkDescartes. (non-breakable, allow multiple spaces)
 * → I thinkDescartes. (breakable, does not allow multiple spaces)
 * What do you think? --Diego Queiroz (talk) 21:01, 4 October 2014 (UTC)