Help talk:Extension:ParserFunctions/2014-2020

#ifexist problem
I'm creating a template to redirect red links to wikipedia, here's the content of the template : theorically if exists output, if doesn't exist output , function seems right isn't it?

practically, it works with one word, for instance it works with, w being the name of the template but when it comes with spaced words such as, output is Page Test Page and link is Test

why is spacing causing issues? I don't get it, if anyone can help me, thanks.


 * Use   rather than hardcoding the enwiki domain.  The actual problem you're experiencing is that the division between the link target and the link text is placed at the first space in the expanded string, so you need to replace spaces with underscores in the first parameter; fullurl will do that for you, and also make the template portable to other wikis. Happy ‑ melon 16:20, 28 August 2011 (UTC)


 * No, it doesn't seem right. External links must not contain spaces. Try using   as part of the url.

Gustronico 20:08, 28 August 2011 (UTC)


 * Fullurl didn't make it. So I tried the solution of Gustronico, the title works but the link doesn't, the space is replaced by a plus sign. It gives Test+Page

Edit : anchorencode works, but it won't work with special characters while urlencode can! If there's any solution it would be great.


 * You can use interwiki linking. I think it is standard to have them to the English Wikipedia, otherwise see Manual:Guide to setting up interwiki linking. On this site: Test page or Test page. If for some reason you want external link style: gives  .--Patrick1 12:06, 3 September 2011 (UTC)

Did you put the |WIKI parameter in urlencode? It would return underscores for spaces: Gustronico 20:38, 3 September 2011 (UTC)
 *   →
 *   →
 *   →
 *   →

Logical OR failing?? (Nope, I just fail.)
Hello. This expression should return "EXPANSION IS TRUE", but returns "EXPANSION IS FALSE":

Likewise, the below code should return TRUE [(1 || 0 || 0 = 1); should be TRUE] but returns FALSE:
 * BOOLEAN ALGEBRA: :
 * SIMPLE BOOLEAN ALGEBRA: :

I'm running MediaWiki 1.16.3 with ParserFunctions (Version 1.4.0). Help! 17:39, 4 August 2011 (UTC)
 * I think you will need to use #ifexpr, as in, which returns:
 * Analogously,  returns
 * Helder 18:12, 4 August 2011 (UTC)
 * Helder 18:12, 4 August 2011 (UTC)
 * Helder 18:12, 4 August 2011 (UTC)


 * Erm. You're quite right here. How embarrassing for me; I've been looking at this for too long and completely missed this. Sorry about that, and thanks for the help! 18:34, 4 August 2011 (UTC)

#time
Why is it that the time function y only works for years before 2000? For example,   yields 08 (currently, when the year changes to 2009 presumably it will yield 09 at that point) when it should yield 02. This is very frustrating when trying to construct things utilizing dates with 2 digits. It doesn't seem to matter for 1999 and before, though. Examples:  </tt> yields  </tt> yields  </tt> yields  </tt> yields Thanks for any help that anyone may be able to provide. I had no idea where to post this question, but hopefully this is the right spot. 24.236.101.233
 * Also, I edit mainly on wikipedia (sorry for not having a username here). If/when this is fixed, would it automatically update on wikipedia or not? Sorry, I didn't know how that worked. Thanks again for any info anyone might be able to provide. 24.236.101.233 09:52, 30 December 2008 (UTC)
 * The problem is that if you use  </tt>, you get, like for   </tt> . <font color="#66A7CC">i <font color="#9966CC">Alex  12:56, 30 December 2008 (UTC)
 * You just need to make the date look more like a date. A 4 digit number staring with a 2 isn't enough. Try:  or  . See strtotime. Splarka 21:35, 30 December 2008 (UTC)
 * It is possible with some minor limitations to use #time for specifying dates from -6999BCE to 6999CE. It requires some template hackery to bypass normal limitations of #time, but it is possible to do.  One limitation is that there is no way of recognizing the precision the editor intended for certain dates and times.  EG: if seconds were specified as 00, there is no way (that I have come up with yet) to tell if the user simply omitted the seconds because they didn't measure with that precision.  For example of the lengths I had to go to in order to get this functionality, see code at .  (Note- you won't be able to see the results of the calculations from preview- the easiest way to see the UTC value emitted is to turn off CSS, eg, Opera View.Style.User mode.  Look for the UTZ value in parens following the visible date-time.) -J JMesserly 20:05, 17 February 2009 (UTC)

I am wondering why the format code "z" delivers the day of the year starting with 0, deviating from the ISO-8601 standard, which counts from 1 to 365 (or 366). Someone recently used this code in the ISO-8601 article, giving wrong results. Question: was the definition here intentionally deviating? If so, how can the correct ISO ordinal date be displayed; if not please revise the magic word. &minus;Woodstone 07:33, 11 June 2010 (UTC)

#switch
Quote from help: ''It is possible to have 'fall through' values, where several case strings return the same result string. This minimises duplication.'' — It doesn't seem to work for me. Instead, an empty string is returned for cases where right-hand side is emty. --Lozman 14:19, 3 January 2009 (UTC)


 * I fixed the description.--Patrick 10:20, 4 January 2009 (UTC)


 * Thanks a lot! Now it works OK. --Lozman 11:11, 4 January 2009 (UTC)

I have used #switch to return one string at and a different one at. This works very well, however one of my strings had a leading space. This was not parsed correctly, the space was ignored. I have had to precede it with a line break for it to work. 213.126.244.228 14:36, 17 February 2009 (UTC)

subsequent cases
I wonder if there is any good reasons why subsequent cases are not supported. They would save some time and Code I think. Think of something like the following: --Danwe 00:26, 18 June 2009 (UTC)


 * They are supported. That example will work perfectly, when you specify a test string as the first parameter. It is not particularly useful, however, because an input of 1 will always match the first case encountered (the "1 foo" case).  However, a statement like this:


 * Will work perfectly. Happy ‑ melon 08:08, 18 June 2009 (UTC)
 * I know that this will work perfectly but this is not what I meant. I meant subsequent cases, match each "1" and not only the first "1". That would be the same behavior than in C++ for example where you can stop it with the break kommand. --Danwe 14:20, 21 June 2009 (UTC)
 * No, the behaviour in languages like C++ is to scroll through the cases until a match is found, then to execute all the remaining statements in the switch until a break</tt> is found. So the output of a statement like your example in C++ would be "1 foo2 foo3 foo1+2 foo1+3 foo" What you want is the output to be "1 foo1+2 foo1+3 foo", right? That's basically just string substitution. How would that be useful? Happy ‑ melon 21:24, 26 June 2009 (UTC)
 * This would be usefull if some cases should have the same output and the output is very long so you don't want to write it down for all the cases. --Danwe 18:48, 5 July 2009 (UTC)
 * Not sure whether this is exactly the thing you want, but I have a simple patch which I belief does this exact thing (I needed it), but it might nearly definitely break some other functionality: replace line 220 ( "return trim( $frame->expand( $valueNode ) );" ) with ($returnvalue .= trim( $frame->expand( $valueNode ) );") and add a line between 241 and 242 containing "if($returnvalue != "") return $returnvalue;". Lastly it might be necessary to add "$returnvalue = null;" at the begin of the function. -- David Mulder (can't login) 77.95.97.53 11:17, 6 January 2010 (UTC)

Example for first black president
The above example should change on Jan. 20, 2009. --Ed Poor 20:40, 9 January 2009 (UTC)


 * That won't because there is no Template:Age in days on this wiki, and even if there were, #if only checks nullity. Try something like:
 *  </tt>
 * Splarka 22:45, 9 January 2009 (UTC)

Using #if to call an image and adding attributes
I am trying to use #if to call an image. I don't want this image to link to its source page or anywhere. I think that I can do that by using "|link=" as an attribute but I can't get it to work. Anyone able to help?


 * if:|[[Image:|130px|]]


 * well, this:


 * Works for me, but note that the link= parameter is new to version 1.14 which isn't released yet. Splarka 08:25, 15 January 2009 (UTC)
 * Works for me, but note that the link= parameter is new to version 1.14 which isn't released yet. Splarka 08:25, 15 January 2009 (UTC)
 * Works for me, but note that the link= parameter is new to version 1.14 which isn't released yet. Splarka 08:25, 15 January 2009 (UTC)

Errrrm - so does that mean that I have to wait for 1.14 and upgrade or is there a workaround? I tried it in mine and it didn't work - you can still click on the image and get through to the Image page, which is what I want to disable :(.


 * Only if you want to wait for the quarterly release, if you're ambitious you can Download from SVN to get the latest version. --Tlosk 10:46, 30 January 2009 (UTC)

Move to Help:ParserFunctions
I don't know if anyone else noticed, but Help:Extension: looks ridiculous. I amend that we move this page to the above link. -PatPeter  MediaWiki Support Team  00:23, 18 January 2009 (UTC)


 * I think the distinction can be helpful in that Help: applies to a default installation and Help:Extension: makes clear that the information applies to an added extension. --Tlosk 10:38, 30 January 2009 (UTC)

HTML in #IF statement branches is not rendered as html but as plain text
In this example I want to include or exclude a row of a talbe based on the presence of a passed paramter:

However what happened is the html is renderes as plain text and I get a bunch of HTML code showing up on my page.

How can I prevent this?

Thanks, Pete.
 * See Manual:$wgUseTidy -- Skiz zerz  21:40, 5 February 2009 (UTC)


 * I recommend using wiki-markup instead of HTML:


 * —Sledged (talk) 00:28, 6 February 2009 (UTC)

Help
This code in a template:

produces this error.

but it still works when the template is used??? --Droll 13:31, 7 March 2009 (UTC)

See w:User:Droll/sandbox1 for template and w:User:Droll/sandbox3 for test. --Droll 15:16, 7 March 2009 (UTC)

Never mind. My bad. --Droll 21:42, 7 March 2009 (UTC)


 * What did you do wrong? I see the error still on your sandbox1 page.  Have you tried to fix it?  --Lance E Sloan 20:44, 9 March 2009 (UTC)


 * What I wanted to do was:


 * Thanks for asking. --<font style="color:#355E3B">droll <font style="color:#704214">&#91;chat&#93; 23:53, 13 March 2009 (UTC)

When I try to use a code like:

I just get the input and no answer. I should get: true, but get  . I think it have some to do with the setting in a file, but I have no idea how to fix it?


 * It is likely that the ParserFunctions extension is not installed on your wiki. Is it listed in Special:Version? Happy ‑ melon 11:50, 11 April 2009 (UTC)

Exactly. Now it works. I used the information from this site about Extension:ParserFunctions

Better Operator table
See Extension:ParserFunctions/Help/sl for a table that is much more helpful in my opinion. --<font style="color:#355E3B">droll <font style="color:#704214">&#91;chat&#93; 23:47, 13 March 2009 (UTC)
 * That operator table is GFDL, which means we can't use it here. If you feel like rewriting something that is similar (but not a derivative work), feel free to put it up here, but because the Help: namespace is Public Domain and the rest of the site is GFDL, we can't just copy/paste it. -- Skiz zerz  23:54, 13 March 2009 (UTC)
 * That is a shame but I understand. I will keep an translated version locally. I think some mention of operator precedence is worth mention. I assume its the same a c?. --<font style="color:#355E3B">droll <font style="color:#704214">&#91;chat&#93; 00:03, 14 March 2009 (UTC)

More versatile #titleparts?
Could the #titleparts: function be expanded to allow other separators than slashes (colons, maybe even spaces)? (Possibly having a third parameter to specify the separator, with slashes as default so as not to break its current use…) -- 87.165.184.244 02:06, 14 March 2009 (UTC)
 * Then it wouldn't be a titleparts function, it would be a string-splitter, which is a completely different concept. String-manipulation ParserFunctions are available in the StringFunctions extension; if you want proper string-manipulation functions, you need to get this installed on your wiki.  Happy ‑ melon 08:17, 14 March 2009 (UTC)
 * Ah. Thanks for the quick reply! 87.165.185.6 01:27, 15 March 2009 (UTC)

#if doesnt works
On my version of wikimedia 1.14, #if option dont works. I'm printing - and nothing happens, text showing only as plain text

Joe.


 * Install the ParserFunctions extension. —Emufarmers(T 21:27, 29 March 2009 (UTC)

I'm having trouble with the same thing. I have ParserFunctions extension installed (see http://wiki.accelereyes.com/wiki/index.php/Special:Version). I have a test page too (see http://wiki.accelereyes.com/wiki/index.php/TEST). What am I doing wrong? Why is it showing only as plain text? '''UPDATE: This error only occurs when I'm logged in. When I'm logged out, everything works fine.'''


 * You're running very old versions of MediaWiki and ParserFunctions. I don't know how they behave. —Emufarmers(T 22:03, 25 January 2011 (UTC)

Rand for #expr:?
Doesn't anyone think it make huge sense to add a Rand function to the #expr: group of functions? Extension:Choose is definitely not applicable (all the hooks are in the wrong places...) and Time-based pseudo-randoms won't work either. I was amazed when I realized this wasn't there yet... Timeroot|undefinedTalk • Contribs • Edit Count 19:28, 30 March 2009 (UTC)
 * Why do you hate the cache so much? The cache loves you, the cache does everything it can for you, and it has to go to work and tell its friends "oh, I just ran into a door". Splarka 07:14, 31 March 2009 (UTC)


 * The original commit of ParserFunctions included a "rand" function. But I removed it, because I thought it would be confusing. People will expect it to work, which of course it won't, due to the parser cache. Random selection is best done with JavaScript. -- Tim Starling 09:09, 1 April 2009 (UTC)


 * I'd like to use it with subst, so if you still got the code, would you share it? --Sidcom 10:58, 1 July 2010 (UTC)

Is it possible to have a 3-tiered approach to parameters (not) passed in to templates?
Given a template that can be used in three ways like this:

is it possible to have the template handle itself differently based on param not being given, param given without a value and param given with a value?

I've been looking at using and  to distinguish the first and second case (the third case handles well), but it doesn't seem to work; the output is the same either way.

It's especially how handles itself when put into an  I'm interested in.

Rafiki 07:57, 16 April 2009 (UTC)


 * "parameter" is
 * Not the usual method of using #if, but that #if will only trigger in your second case. Note that I edited your example above, because your second case was actually a different parameter, it was assigning "param" to . If you really did mean that, that is a different barrel of fish. Splarka 08:16, 16 April 2009 (UTC)


 * On enwiki we tend to use the "logical negation" ¬ character that's found at the top-left of most keyboards. Since it's not something that anyone is ever likely to actually pass to a parameter.  So you could test for your three separate conditions like this:


 * Does that make sense? Happy ‑ melon 10:08, 16 April 2009 (UTC)


 * Even if it may not make sense, it works like a charm. Many thanks for the insights! And you are, of course, right about the assignment of "param" to ; I didn't consider that at all. Rafiki 13:30, 16 April 2009 (UTC)

To distinguish between defined (and possibly empty) and undefined, use:
 *  </tt>.

Patrick 11:00, 14 July 2010 (UTC)

limits of #titleparts
There seems to be a limit for the #titleparts-function. These two lines of code should produce the same result ...:

... but only the second one seems to work correctly:

Is there a limit of string-length? Or a limit to the number of segments? And if there is a limit, (how) can I change it? I have to use #titleparts because I want to receive longer substrings like "2/3/4/5" and with #explode it is only possible to get one piece based on its position. Sorry for my lack of English. --213.39.183.144 17:39, 2 May 2009 (UTC)


 * The function only performs a maximum of 25 splits, so no more than 26 segments can be created:
 *  </tt> &rarr;
 * The string must also be less than 255 characters in length. Hope this clarifies. Happy ‑ melon 11:32, 3 May 2009 (UTC)


 * Thanks for the quick reply. Is it possible to change the maximum string-length and maximum number of splits? --80.171.78.168 12:12, 3 May 2009 (UTC) and why do I have a completely different IP today? --80.171.78.168 12:13, 3 May 2009 (UTC)
 * The number of splits is hardcoded into trunk/extensions/ParserFunctions/ParserFunctions.php (line 504); you could change it, but you'd have to remember to change it every time you updated the file. The maximum string length is essentially unavoidable: the string is converted into a Title object to check its validity (it is supposed to be a page title, after all :D</tt>), and the maximum title length is a function of the database field width.  Happy ‑ melon 16:35, 3 May 2009 (UTC)
 * And if you want to avoid being confused (or confusing others) with a dynamic IP, why not create an account?? It takes literally ten seconds, and gives you all sorts of cool features... Happy ‑ melon 16:35, 3 May 2009 (UTC)
 * Again, thank you for the quick reply. Maybe it is possible to avoid the conversion to a Title object? So, it would be possible to use links and and other stuff within the string ... I'll try this. Greetings, --WiMu 10:16, 4 May 2009 (UTC) and where is my IP today? ... ah, it's my new account now ;-)

#ifexpr for strings
Would be great if #ifexpr would be enabled for strings as well. Imagine string comparison like  --Danwe 14:48, 4 May 2009 (UTC)


 * And what would be the expected logical value of  </tt>?? :D</tt> Happy ‑ melon 17:05, 4 May 2009 (UTC)


 * False. In this case we can look at the 1 as string and the strings "one" and "1" are not equal. I only don't know if we should define that  is nonsense and will lead to an error message or if this has a meaning as well for example comparison of the string lenght. --Danwe 13:17, 5 May 2009 (UTC)
 * There is only one problem I can see: The and and or words. They shouldn't be interpreted as strings. A way to avoide that could be to set strings into quotes like . It should be possible to use and and or for strings as well and also mixed with number comparision like    --Danwe 13:44, 5 May 2009 (UTC)


 * Hmn, with quotes, it could perhaps work, although there is still some rather wierd logic available ( </tt>??) We'd need to define an appropriate string&rarr;integer cast for such expressions, which should probably be the same for all strings.  Casting to true makes some sense, as would casting to the binary representation, but both allow some rather odd concepts (division by a string?!?).  Casting to an error avoids that problem, but makes them essentially unusable. Casting to different representations based on the calling operator could be at best described as "quirky"... Happy ‑ melon 17:15, 5 May 2009 (UTC)
 * I think it's not neccessary to compare "1" and 1, sting and non string. Because the template programmer knows what he want's to compare he should know at least whether he wants to compare strings or numbers. And if you have a string with unknown content which perhaps could be a number it doesn't matter because it could be a real string as well which you must compare as string anyway. And casting integer into string is no problem in the template, the quotes do it so it's save in any case as long the user won't forget the quotes. --Danwe 17:40, 5 May 2009 (UTC)
 * Casting integers to strings for comparison is a good idea, but has its own set of problems. What does   </tt> evaluate to?  Or do you mean only explicit casts (using quotes) would avoid an error? That's more tenable, but what if the input strings contain quotes themselves? Don't even think about suggesting we escape them... :D</tt> Happy ‑ melon 22:11, 5 May 2009 (UTC)
 * "(1 and 2)" is a string, not a logical comparision which is converted into string after the comparision. You can write: 1 and 1 and "abc" because with and and or you only compare boolean results. But your last point was one I never thought about. What if there are user defined quotes inside the quotes... i agree, escaping them won't work. " inside of ' quotes could be possible but then we have the same problem with the ' quotes... honestly I have no idea yet --Danwe 18:42, 6 May 2009 (UTC)

Request: new flag to force date interpretation in #time
Is it possible to add a flag (may be xd) to force date interpretation of ambiguous inputs like four-digit and six-digit numbers, giving an error when that number is not a valid date? It should be a toggled flag like xN and it should work as follows: Feel free to correct my English. Gustronico 00:42, 21 May 2009 (UTC)
 * <tt> </tt> &rarr; 2006 instead of  Fixed since 86805 24 April 2011
 * <tt> </tt> &rarr; November 2006 instead of 
 * <tt> </tt> &rarr; Error instead of 
 * <tt> </tt> &rarr; 1998 04 01 00:00:00 instead of 
 * <tt> </tt> &rarr; 1998 01 01 00:00:00 instead of 


 * Well, don't waste your time. I've solved the problem with <tt> «ambiguous number» </tt>
 * Note: #time: function is omitted for simplicity. Refer to cases above.
 * <tt> 20060000 </tt> &rarr; 20060000 &rarr; 
 * <tt> 20061100 </tt> &rarr; 20061100 &rarr; 
 * <tt> 20061500 </tt> &rarr; 20061500 &rarr; 
 * <tt> 19980400 </tt> &rarr; 19980400 &rarr; 
 * <tt> 19980000 </tt> &rarr; 19980000 &rarr; 
 * Nevertheless I think that it would be a usefull flag. Gustronico 16:08, 21 May 2009 (UTC)

Division
How much is:



There seems to be an error in the info box which lists /div as a binary operator. Shouldn't that be / div with a space between the slash and the letters? Ed Poor 21:57, 25 May 2009 (UTC)
 * Yes. Happy ‑ melon 22:16, 25 May 2009 (UTC)

Rounding
Is all rounding to the nearest integer, or what?

=

Where is this documented? --Ed Poor 22:03, 25 May 2009 (UTC)
 * meta:Help:Calculation, hasn't been moved over from meta yet. If you want to write a PD version here, we'd be very grateful! Happy ‑ melon 22:17, 25 May 2009 (UTC)

Import from StringFunctions
The features of StringFunctions have been imported as of r50997 (probably MW 1.16). The documentation will need to be merged when it is released. GreenReaper 17:35, 31 May 2009 (UTC)
 * Don't hold your breath on it surviving to a release... Splarka 07:12, 1 June 2009 (UTC)
 * That's what I was going to say: I want to see it get through code review before I put any work into documenting it. The documentation can't be "merged" because they're incompatible licenses (Help: is public domain), so it'll have to be written from scratch. Happy ‑ melon 08:53, 1 June 2009 (UTC)


 * Well if someone wants to point out terrible flaws, please do. The code was almost totally rewritten from the StringFunctions implementation (which was just plain terrible in some places).  In the meantime, the bastardized string manipulation templates are now being used on >20,000 enwiki pages and that will almost certainly continue growing until we either have real string functions or Brion changes his mind and kills off the padleft: abuse that made those possible.  In the mean time, if someone does start working on this documentation please ping me and I'll certainly check it for accuracy and make sure it covers all the appropriate quirks.  Dragons flight 21:33, 1 June 2009 (UTC)
 * Presumably we eventually need Help:Extension:StringFunctions anyway, so I guess we might as well start. The way the string function implementations on enwiki have grown is a very clear sign of just how valuable these methods are.  But I'm not breaking out the champagne until I see  as "3" right here.
 * Incidentally, do you know why Wikimedia's MW is lagging so far behind SVN trunk? We're 2,500 revisions behind now... <tt>:(</tt> Happy ‑ melon 22:19, 1 June 2009 (UTC)
 * Once Upon A Time, the developers were told that some simple ParserFunctions would reduce the instances of ugly <tt> </tt> type templates and simplify the codebase of templates, and make everyone live happily ever after. They initially and very briefly made code simpler, but then made templates a thousand times more complex (see any template on en.wp).
 * Adding StringFunctions will only add to the insane complexity, and turn Wikimedia's wikicode into a natural language parsing system, making templates almost impossible for anyone to edit safely, and giving the servers even more very inefficient overhead. Certain developers absolutely do not want this, as this would only make things more complex in the long run, and more system intensive. They seem to prefer playing a "But this isn't up to snuff" game on bugzilla. If you want a more frank admission of the reasoning, please see This log starting at about <tt>[16:45:35]</tt>. This almost certainly will be reverted (again) before scap, and if not, domas will probably come along later and cripple the features after tracing the crazy profiling spikes. My guess anyway.
 * Also, brion has been very distracted for about 7 weeks, what with dev meetups and getting hitched and all. Splarka 07:23, 2 June 2009 (UTC)
 * Hmm, seems Brion's actually more amenable to the idea than Tim; and it seems to be a fairly even split amongst the senior devs. As I said, I'm definitely keeping the champagne in the bottle for now.
 * I didn't know Brion got hooked up! Congrats to him.  Is there more to read into <tt>[12:01:49] he's also not back permanently, I think he's heading somewhere</tt>?? Is that just his honeymoon or is our venerable leader leaving us??  <tt>:S</tt> Happy ‑ melon 09:21, 2 June 2009 (UTC)
 * Last week was part of his honeymoon, as I understand it. Unless there is evidence to the contrary, I'd just assume he was off having a good time.  I think you are correct that Brion is generally supportive of StringFunctions in concept, as long as the implementation is reasonable.  The past implementations had serious flaws that generally made them unsuitable for use at the WMF scale.  I'm hoping that the new version is technically acceptable, so the only concern is more of the "do we want this variety", and I think the community can have a significant voice in that.  Dragons flight 23:13, 2 June 2009 (UTC)

(Undent) See 51497 for latest developments. I still think you should wait to see if it makes it to a release before going through the trouble and clutter of adding them here. Aside, this would mean the deprecation of the StringFunctions extension... but still, the (totally obvious) main goal of sneeking these in to Wikimedia is as yet unfulfilled. Splarka 12:24, 5 June 2009 (UTC)
 * I am still failing to see why these two extensions have been merged, except as you say as a broad-daylight attempt to sneak them onto WMF as part of normal code review/scap, rather than an explicit shell request. Which Tim has now just foiled.  The two function sets are radically different, and yes, enabling them is as much a philosophical/ideological step as a technical one.  Either way, nothing is going to happen without Brion's say-so. Happy ‑ melon 15:32, 5 June 2009 (UTC)


 * I'm not actually sure either (and I'm the one that merged them!). Comments at 6455 favored such a merge, as did devs I spoke to privately before doing it.  I don't "think" the intent was merely to backdoor them in (it certainly wasn't my intent anyway, and it should be obvious to any reasonable person that this would immediately draw discussion and hence couldn't actually be accomplished as some secret plot).  Personally, I would have been just as happy to implement it as a separate extensions, and even think that seems more natural.  Dragons flight 02:29, 6 June 2009 (UTC)

Using July 27, 2024 in ?
I want to show diffent content each day, for example:

But every time i save the template the code is changed and does not work! --80.228.185.14 20:19, 10 June 2009 (UTC)


 * It is impossible for anyone here to help you with only that desciption of the problem. How does "the code change"?  What does it do instead of work?  The more information you provide, the more likely we are to be able to solve your problem. Happy ‑ melon 22:54, 11 June 2009 (UTC)
 * Hi Happy-melon, thanks for your reply. The code changes to the following

}} --80.228.182.220 15:32, 12 June 2009 (UTC)
 * 10062009 = Content 1
 * 11062009 = Content 2
 * That is extremely odd. Can you provide a url to the wiki where you're experiencing this problem? Happy ‑ melon 16:31, 12 June 2009 (UTC)
 * Just look here: http://gzsz-wiki.de/index.php/Sandkasten. The code only changes if you save a page. in preview-mode the code works. maybe a plugin causes the changes? --80.228.183.126 07:40, 13 June 2009 (UTC)
 * To be honest, it's probably something wrong with one or more of the wierd-and-wonderful extensions that are installed there, most of which are not WMF-stable. What happens if you try and remove just one of the extra braces? Happy ‑ melon 08:12, 13 June 2009 (UTC)
 * If i remove just one after saving there are three of the braces. ;-) I'll try to deactivate the plugins to check if of of them produces the error. --80.228.183.25 19:55, 13 June 2009 (UTC)
 * Yeah, the errors suffer from the autolink-plugin. i deactivated it and now it works. --80.228.182.105 09:42, 16 June 2009 (UTC)

Switch and Parameters/Arguments
Is there anyway to use switch with a passed parameter/Argument? Something like:
 * --71.187.221.128 23:13, 13 June 2009 (UTC)


 * Exactly like that. Splarka 07:36, 14 June 2009 (UTC)

Setting timezone
Hi.

Shouldn't this give different results?

Just as does this:

--Nux 23:36, 30 July 2009 (UTC)

Parameter with #expr
I have a parameter in my template, say. How can I use it with #expr so that when =20

produces 10? All I get is the error: Expression error: Unrecognised punctuation character "{"


 * It will work when transcluded. If you want it to work on the template page, give it a fallback default like, or wrap it in noinclude tags. Splarka 07:19, 5 August 2009 (UTC)


 * That seems to do the trick. Thank you!

This worked for me too:

Thank you. Errectstapler 21:40, 12 May 2011 (UTC)

Internal link in Template - not working
I created a following template, modeled after w:en:Template:Missing_information. I wanted to add a parameter "anchor" so I could jump to a section on the talk page. But when I try to use it, I get garbage instead of an internal link like Talk:Pagename#Section

Expensive parser functions
How can the number be changes?--Launchballer 19:56, 11 September 2009 (UTC)


 * As it says very clearly on this help page, by changing <tt>$wgExpensiveParserFunctionLimit</tt>. See Manual:$wgExpensiveParserFunctionLimit for more details. Happy ‑ melon 21:31, 11 September 2009 (UTC)

Conditional statements inside math functions
I am trying to create a template while using a conditional statement inside of a math tag ( $$...$$ ), but I'm having problems. It seems like the math tags are running before the conditional statements, but after receiving the other parameter values from the template. Here's the code, which can be found at Template:DentalFormula:

This yields the error: "Failed to parse (lexing error): \tfrac{ }{ }"

Am I doing something wrong? Is there any way to fix this? –Visionholder 03:47, 16 September 2009 (UTC)
 * You can't use template parameters directly in a parser extension tag. You have to convert it to a parser function with #tag. Splarka 07:03, 16 September 2009 (UTC)


 * You absolutely rock! I never would have figured that out.  Thank you! –Visionholder 08:41, 16 September 2009 (UTC)

Bug?
Is this the expected behaviour?
 * <tt> $$\unknownname$$ </tt> &rarr;  $$\unknownname$$
 * <tt> </tt> &rarr;  

I mean, if the math formula returns an error, should #iferror return "error"? Helder 17:18, 29 November 2009 (UTC)


 * It's not ideal, but it is expected. Extension tags like <tt>  </tt> are processed after parser functions like iferror, so when the function is evaluated, the input string is just "<tt> $$\unknownname$$ </tt>", not the expanded HTML with error class.  Other tags, like <tt>  to get only the first title part of the page, but it somehow didn't work out. does anyone know why? 87.177.222.84
 * You probably don't have subpages enabled in the namespace you're trying to use the function in. Happy ‑ melon 23:00, 1 March 2010 (UTC)

Switch default
Guys, I think the implied default is broken. I had to use the explicit "#default". Check it out, in case I'm right. --JokerXtreme 12:32, 4 March 2010 (UTC)
 * . I bet your implied default contains an equals sign. You must use "#default" if the implied default contains an equals sign, as this is normal behavior (the first equals is always the delimiter). Splarka 08:06, 5 March 2010 (UTC)

#denamespace
Is there a way to convert a page name to its name without the namespace? For example: Category:Extensions                     >    Extensions Help talk:Extension:ParserFunctions     >    Extension:ParserFunctions Unfortunately, "#denamespace" isn't an actual function, so I was wondering if there were ways to do this. Regards,   A rbitrarily 0    ( talk ) 00:51, 6 March 2010 (UTC)
 * Please refer to Help:Magic words. Hamilton Abreu 23:25, 8 March 2010 (UTC)
 * Ah, thanks! I didn't think of using this.  For those of whom it interests,  can be used to do this.  For example  yields <tt></tt>.  Cheers,    A rbitrarily 0    ( talk ) 16:28, 9 March 2010 (UTC)

#time utc offset bug
TimeCurrency 18:28, 12 March 2010 (UTC)
 * result 2010-03-11 13:30:00
 * result 2010-03-11 13:30:00

Splitting
is there something that would split a number up. link if i had 1923 and make it 1, 9, 2, 3 or something? Gman124 20:27, 16 March 2010 (UTC)


 * Use "y" to get 23. For everything else, there's Extension:StringFunctions. :) --Church of emacs talk · contrib 20:31, 16 March 2010 (UTC)


 * ok thank you. —The preceding unsigned comment was added by Gman124 (talk • contribs) . Please sign your posts with ~ !


 * See also m:Template:Digit.--Patrick 09:59, 12 September 2010 (UTC)

new section
when i use these functions on my language wiki, the time always comes in the my language's number form so these always mess up. So, is there a way to make the time come in english numbers or make these or make these functions right?

like for the following:

it should give

but on my wiki it gives an error because 2024 giving ੨੦੧੦ as year value so get error like

so is the expr thing expecting 2010 instead? and how would that be fixed. so that it takes the value in my language. or is there a way to turn number from one lagunage version to another? Gman124 21:13, 16 March 2010 (UTC)

Check Username
Is there a way (a magic word maybe?) to make an if-function that checks the username? Like: if username=thisname show that.
 * Yes, it's possible to display something according to the last page editor, with, but for more you'll need JavaScript. JackPotte 18:40, 11 May 2010 (UTC)

titleparts misinterprets underscores
=, but it should be. This is buggy behaviour when handling with URLs. A fix requires ugly double replacing. --Subfader 13:50, 18 May 2010 (UTC)


 * Would using:
 * depending on where in the url you're going to place it, be of any help? Hamilton Abreu 15:06, 18 May 2010 (UTC)
 * depending on where in the url you're going to place it, be of any help? Hamilton Abreu 15:06, 18 May 2010 (UTC)
 * depending on where in the url you're going to place it, be of any help? Hamilton Abreu 15:06, 18 May 2010 (UTC)


 * I know how to fix it, I just wanted to report it. Dunno if this is intended behaviour tho. --Subfader 12:21, 19 May 2010 (UTC)

Another bug:  = , but it should be. I also know how to fix this but it's just too much of "smart" behaviour :( --Subfader 23:13, 19 May 2010 (UTC)
 * Ok, I see. But reporting it here will yield no results. Please report all MediaWiki bugs in bugzilla. Hamilton Abreu 01:42, 20 May 2010 (UTC)


 * Done. I wasn't sure if all this is intended behaviour tho. --Subfader 12:11, 20 May 2010 (UTC)
 * To be honest, neither am I. Hamilton Abreu 13:59, 20 May 2010 (UTC)

switch Foo & Bar!=...
I want to use #switch for page names, but it doesn't work for me when the title uses & (and !) ( Category:Foo & Bar! in this case): I tried using |Foo & Bar|=Bar, but that doesn't do the trick either. Anyone knows a workaround? It works with and  Foo_%26_Bar! but actually I want to keep using. --Subfader 17:28, 5 June 2010 (UTC)


 * for  you have to use  . These are (currently) the only three characters allowed in titles that need to be escaped for XML/html parsing. A quick way to see the raw comparison is to use Special:ExpandTemplates which gives you the 'result' pre-rendering, eg here. Splarka 07:29, 6 June 2010 (UTC)


 * Aaah. Thanks for enlighting me :) --Subfader 20:02, 6 June 2010 (UTC)

using #time in other languages
I tried to use #time word for tamil but its throwing error. gives something like ஜூன் 7 (=June 7) passing throws error. How can i achieve it? thanks -Mahir78 07:09, 13 June 2010 (UTC)

#time limit
There seems to be a limit on the number of occurrences of #time in a single wiki page. This was observed on the Wikipedia page List_of_oil_spills (see the changes in this difference: http://en.wikipedia.org/w/index.php?title=List_of_oil_spills&action=historysubmit&diff=368179588&oldid=368005766).

The page contains a huge sortable table of dates, using the template, which was using #time to help parse its input parameters (in the form yyyy-mm-dd). After the table grew to a certain size, we started seeing "Expression error: Unexpected < operator" cropping up in templates down in the reference section. (This error wasn't very helpful, so we couldn't figure it out.) Eventually the table grew big enough that we got a "Error: too many #time calls" in one cell, which was more helpful. This enabled us to fix the problem by changing the input parameters to the form yyyy|mm|dd, which doesn't use #time.

I don't know why there's a limit on #time, but I suggest discovering the source of the limitation and posting it on this ParserFunctions page, to help others who might encounter this problem.

(Wikipedia user: Johnson487682) 12.199.176.12 14:28, 15 June 2010 (UTC)


 * Done.--Patrick 10:04, 12 September 2010 (UTC)

Understanding this page for non-computer programmers
In my edits, I have tried to address what this I feel this page needs:
 * 1) Real life examples.  → Baz is too complex, and is not as good as real life examples.
 * 2) Explanation of the practical uses of these parsers. What can be done with these parsers?

I added to the switch section in an attempt to make this page easier to understand. Adamtheclown 17:14, 1 July 2010 (UTC)
 * At the very least, such examples shouldn't be enwiki-centric, because not so many people in the world know what the hell infobox is. Max Semenik 17:23, 1 July 2010 (UTC)


 * Hi Adamtheclown. I understand you put a lot of work into creating this material and recognized so in the initial rollback comment. Your continued contribution to improve the documentation is welcome, but I believe this was not the case here. Could you please consider the following:
 * Examples should as simple, clear and concise as possible. Simply put, the examples used are confusing; altogether, they use two templates and three pages to attempt to illustrate a basic use of #switch. It took me several reads just to understand what they are trying to demonstrate. They also require an understanding of templates, template parameters, named template parameters, wikitable formatting and magic words just to read them. None of this helps understand, nor is central, to what the function does.
 * Real life examples go at the bottom. It is illogical to interrupt a description of the function and present to readers three complex examples of its use, before that function has been described.
 * Being in the wrong place and not being simple, clear and concise, these examples actually have the opposite effect to what you intend: they are unhelpful and distract and confuse the reader.
 * Now, generally I agree with your key points of real life examples and practical uses. But surely you know that if we were to do so for all functions on this page in the manner of these examples, the page would more than duplicate in size and become dense and probably unreadable.
 * At all times, we're trying to reach a balance between two extremes, those of being clear and of being real, and it's difficult. But if you're gonna fail one way or the other, you should fail in the latter, not in the former. For example, please consider that users usually come here in order to understand a real life example they found elsewhere.
 * And it's natural that at times different people will have different views on this. But if you understand the points above, you'll surely understand that, for the benefit of the page as a whole, the edit should be rolled back again. However, I will leave it up to you to please do so. Hamilton Abreu 19:13, 1 July 2010 (UTC)
 * Thank you for your comments, is there anyway to make a real life example which is easier to understand? A middle ground between my "confusing" real life examples and → Baz which to me, is much more confusing.
 * Imagine yourself being first introduced to parser functions, with little computer programming experience, is the current format descriptive enough to teach you how to learn? For me, the answer was no. I had to go to wikipedia and look for examples, and ask on village pump how to use these functions.
 * RE: "It is illogical to interrupt a description of the function and present to readers three complex examples of its use, before that function has been described."
 * By bottom do you mean bottom of the page?
 * My attempt at improving this page, was simply an attempt, and was not the ideal examples, I just saw the page as being to complex right now. Lets work together to come up with better examples, which makes the page easier to understand. Examples could maybe be collapsed in each section.Adamtheclown 15:12, 2 July 2010 (UTC)

Examples of use
How can examples of switch be written more clearly? Feel free to completely start from scratch.


 * Adding information from several templates into one template

Switch will also allow an editor to add information from several templates which have the {{#switch:{{{out}}} coding into one template.


 * Pages with the same name as the template

If the page has the same name as the template, the editor can use {{PAGENAME}}

Uses
Each section would benefit from a short blurb on what the parser function can accomplish.

I retained this, one of many uses for switch:


 * # switch allows an editor to add information in one template and this information will be visible in several other templates which all have different formatting. Ref: Embedded template, Wikipedia:Village Pump (technical), (24 June 2010).

Adamtheclown 15:17, 2 July 2010 (UTC)


 * Adam, thanks for this. Answering your points in turn:
 * Personally, I find the use of "foo", "bar", "baz" and "quok" rather distracting. My brain reads "foo" and "bar" and proceeds to shuts off, requiring a reset. But they seem to be deeeply ingrained in the minds of programmers, coming from early C times, possibly earlier. The /pt version of the PD help uses examples like:
 * <tt> →   </tt>
 * <tt> →   </tt>
 * <tt> →   </tt>
 * Don't know how you feel about those, but to me they're as simple as one can get, while fully illustrating what  section. If you go there, you'll notice a note that already directs the reader to two real life examples, the first meant to be simple and the second more complex. How do you feel about those?
 * This is an interesting challenge, which I cannot raise up to for lack of availability. But the challenge rests on you. I can, however, provide a couple of suggestions.
 * Being real, they should point to real implementations, as is done in the two just mentioned.
 * Because they may change in future, we could use permanent links. Building real life examples in this page will cause clutter and is prone to natural errors (your examples contained some syntax innacuracies such as, which would be avoided).
 * Because this is an opportunity for plugs, we could restrict them to wikimedia wikis. Perhaps just to mediawiki.org, since we already have template mediawiki to connect here from the PD help pages.
 * We could perhaps not just point users to them (as is done in the section), but also explain what  is being used for, in them.
 * There may be even better or simpler examples out there. The challenge is in finding them.
 * Rather than a note, we could perhaps agree on a bottom section for every function with up to 4-5 examples, or something like that.
 * Hamilton Abreu 13:27, 4 July 2010 (UTC)
 * really excellent points! Errectstapler 21:38, 13 May 2011 (UTC)

more examples and slight rewrite
Added and clarified with the following:

Errectstapler 21:37, 13 May 2011 (UTC)


 * Originally it said "If .. Otherwise .." Now you say something only partly true ("The comparison is made as text"), then formulate an exception. The first seems better.--Patrick1 13:41, 15 May 2011 (UTC)


 * Hi Errectstapler, I second Patrick1's comment above, and find the addition of "text", "number", "parameter", "example" and "warnings" sub-headers visually unhelpful. I took the liberty of undoing your edits, but retained two useful things: the calls for the reader to notice the similar numerical examples, and the practical example. I hope I've managed to retain the spirit of your edits, while keeping the section congruent with the remaining sections of the page. Hamilton Abreu 02:06, 16 May 2011 (UTC)

Operators, again
It's taken me a long time to understand some of the operators listed in the table at the top-right of the page. In my opinion there could be much better documentation either inside the table or in the text of the article. I'm I retired "programmer" with a BS in computer science but most of my experience was in c, FORTRAN, and various database languages. I expected the div operator to perform integer division (as in c). I doesn't of course. I seems to be identical to the / operator It treats numbers as reals. Mod is a quasi integer operator because the output is an integer although the input can be a real. The comparison operators only work on numerical data. It would be nice some worked on alpha data. Of course #ifeq: can be used for equality. The warning about floating-point errors is hard to condone but at least its documented although the circumstances under which failure can be predicted are not well defined (it says it depends on the server?). You can get away with almost anything if its a well documented constant behavior. I'm far from throwing up my hands and walking away but I find the current state of the documentation unforgivable. I know that coders are notorious for the failing to document but, in my experience its essential to have a go to documentation person. On one job we had a women who could not code to save her life but she was a wizard at documentation and so was a valued employee (almost indispensable). There should be someone around here like that. People like that are worth their wait in gold. (Rant over and I feel much better.)<font style="color:#355E3B">droll <font style="color:#704214">&#91;chat&#93; 09:04, 5 July 2010 (UTC)
 * I guess clicking the links to Help:Calculation, the floating-point bug description, etc was just too much work for you?
 * 131.216.14.1 17:37, 25 August 2010 (UTC)
 * Dickish responses like 131.216.14.1 is the part of the reason this article is so shitty. Errectstapler 20:14, 12 May 2011 (UTC)

Numbers and magic words
I face some problems when using #expr with some number formats like Arabic-Hindi ( ٠,١,٢,٣,٤,٥,٦,٧,٨,٩ ). This also arises when using some magic words such as CURRENTWEEK, which I believe produces numbers in the previous format. Is there a solution, or how can I change my default numbering format?--Email4mobile 17:05, 15 July 2010 (UTC)

Checking #tag for errors with #iferror doesn't work
I have a tag extension which returns an valid error in some cases. So I tried to use it with #iferror like  but it always returns no error. When I copy the output of  into the #iferror function it works fine. I use MW 1.15 --Danwe 09:53, 25 July 2010 (UTC)

#expr
How can I get a decimal number produced here to a certain amount of decimal points?--Launchballer 20:09, 1 August 2010 (UTC)


 * With round.--Patrick 12:41, 2 August 2010 (UTC)


 * <tt> </tt> →


 * Told you the operators could use some documentation.  –<font style="color:#355E3B">droll <font style="color:#704214">&#91;chat&#93; 20:12, 2 August 2010 (UTC)

#ifeq Problem
When I try something like this: Then this is what shows up:

When it should read: And the reasonwhy this is happening is because of the two pipe characters that are next to each other but are for different kinds of formatting but MediaWiki gets mixed up with the formatting and causes a problem. So is there a solution to this? --Ultra Dot 15:00, 30 August 2010 (UTC)
 * Yes. You need to escape the pipes that relate to the table, so that they are not interpreted by the parser. In most wikis, the template ! exists for precisely this purpose. So:

<pre style="margin-left:50px;">


 * should work. Hamilton Abreu 16:00, 30 August 2010 (UTC)
 * Hamilton Abreu beat me to it. Note that the "pipes" (template) should appear at the beginning of a row, as where you'd put them in a regular wikitable. -DePiep 16:44, 30 August 2010 (UTC)
 * Doesn't seem to work the same way on wikia wikis, so I am asking this question: Do wikia wikis use MediaWiki? (NOTE: I am trying to use it in a wikia wiki) --Ultra Dot 10:11, 31 August 2010 (UTC)
 * Yes, they do use MW. I guess Template:! doesn't exist there. --Danwe 11:00, 31 August 2010 (UTC)
 * They do use it. But when I tried doing the suggestion it started showing up on all pages even if the page title (string 1) is different from string 2. --Ultra Dot 13:25, 31 August 2010 (UTC)

Expensive Parser Function: What_if_logically_not_executed?
I put a question at a Manual_talk, but it seems to be out of the loop. Could someone take a look overthere? -DePiep 14:06, 4 September 2010 (UTC)

Why doesn't negative time work?
If I use the function and I write

the output becomes 8 June naturally. And if I write

the output becomes 9 June. However if I write

the output doesn't become 7 June as expected, but a big Error: Invalid time. Why on earth is that? On "my" Wikipedia (Swedish language version) it seems to work for some months (for instance, June works, but January doesn't) but on the English, it doesn't seem to work for any month at all. Could somebody shed som light on this please? /Ludde23 18:14, 13 September 2010 (UTC)


 * The help page states "The <tt>date/time object</tt> can be in any format accepted by PHP's strtotime function." This link states that "The function expects to be given a string containing a US English date format [...]." So,
 * <tt> </tt> &rarr; 
 * <tt> </tt> &rarr; 
 * <tt> </tt> &rarr; 
 * seems to work. Could this be it? Hamilton Abreu 02:39, 15 September 2010 (UTC)

#time a day out with dates in certain months!
Hi.

If I feed 25 September 2010 in via it returns Friday 24 September 2010. Inputting 4 October 2010 returns Sunday 3 October 2010. So both are one day out! But if I feed 3 November 2010 in it returns Wednesday 3 November 2010, which is the correct day. Any idea what is going on here? I'm running MW 1.15.3 and PF 1.1.1 Mitchelln 15:44, 27 September 2010 (UTC)

Any way to get the username?
Is there any way to detect the username of the person looking at a given page, so you could have the code respond "Greetings, " for example? This is a basic programming exercise, so I was surprised that there doesn't seem to be any documented way to do it with Mediawiki, unless I just haven't been looking in the right place.


 * Search CURRENTUSER and find the variables extension. --Subfader 16:41, 27 September 2010 (UTC)
 * There's a variable "currentusers" but that generates a list of all users who are currently logged in, not the ones who are looking at a given page. On the English Wikipedia, there's a variable "currentuser" but that seems to return the last person who edited the page, not the person looking at it.

How to refer to / check on Semantic Properties?
I'm currently having problems to display a HintBox-Template based on the Semantic Property Values set for a page. How do i refer to the Property and do a comparison in a IF-Function.

Example: The Property: PageStatus

The possible Values: Draft, Review, Release

Result: Depending on the Property state a small hintbox should appear on top of my article. I'm not sure if i should use if, ifexpr or switch here (tendency going to "switch"). --Fennyface 09:12, 27 October 2010 (UTC)

Puzzled by different results on #ifeq related to whitespace and nowiki
I saw this example, and it doesn't make sense to me:

Original:


 * -  - Manually retyped to make sure the spaces were real

Isn't this what it looks like after the nowiki is removed?

Can someone explain why these #ifeq expressions above are not equivalent, and why the last one returns the expected result, and the first two don't return equal?

— User:173.116.103.237, 17:19, 8 December 2010 (UTC)


 * I think the &#60;nowiki/&#62; tags are temporarily expanded during parsing, using unique identifiers, with the effect that they are each treated as non-identical. — Richardguk 19:54, 8 December 2010 (UTC)

Where is #tag documentation
I couldn't find #tag in the list with #if, #ifeq, etc. Where is it documented?


 * Help:Magic words.--Patrick 09:49, 19 December 2010 (UTC)

Declaring variables?
Is there a possibility to declare variables with the Parser Functions (or maybe an extension)? An example:
 * if  is "foo",   should be red and   50
 * if  is "bar",   should be green and   100
 * at the end of the code, there is one code for all cases, like this:

At the moment, I have to write a code like this: I hope you understand what I want to say.--Harmageddon 13:41, 20 February 2011 (UTC)


 * #vardefine is way easier: . Then use    and  . --Subfader 16:20, 21 February 2011 (UTC)


 * I think questions to the extension are better off in the support desk, so I transcluded this and replied there, please check: Project:Support Desk. --Theaitetos 21:15, 25 February 2011 (UTC)

Rounding to 1000
I want to round to even thousand units, e.g. 12,345 should become 12,000 or 123,456.9 > 123,000. I thought something like this would work:  (as here). --Subfader 13:06, 6 March 2011 (UTC)


 * Fix:  --Subfader 17:48, 6 March 2011 (UTC)

iftrue
Isn't there also a <tt> {{#iftrue: </tt> function? Mglovesfun 13:50, 2 May 2011 (UTC)


 * No, although there was a template by that name on the English Wikipedia several years ago. —Emufarmers{{sup|(T|C)}} 22:14, 2 May 2011 (UTC)

Fully (recursively?) substituting within a switch
Hi, I'm trying to write a template that will randomly substitute one of four messages. I've got the random part down by using a mod function with time, but I can't get just the text to substitute. When I call it with a, it grabs a new time and therefore a new message. It seems like a recursive template as in the docs, and I've tried every combination of subst: I can find anywhere in the template, and I still can't get it to work. I'd even settle for leaving the switch function in place and substituting the mod time value, but I can't even get that to work.

Template so far:

Thanks! Staeiou 03:44, 11 July 2011 (UTC)
 * Figured it out, turns out you have to subst everything and put includeonly tags around the entire template. So behold, a random template generator:

{{subst:#switch: {{subst:#expr:{{subst:#time: s}} mod 4}}
 * 0=message0
 * 1=message1
 * 2=message2
 * 3=message3
 * Staeiou 19:16, 11 July 2011 (UTC)

Trimming
I wish the parser functions did not trim the leading/trailing spaces and other characters. I am having trouble adding spaces and paragraph marks on these functions. Ganeshk 15:51, 24 September 2011 (UTC)

Using #if to generate conditional table rows
I'm running into a problem using #if to generate multiple conditional rows in succession. The issue, I believe, stems from line breaks, or lack thereof. If you use line breaks to separate the #if statements, new rows created with |- will appear correctly, but when the condition is false, the line breaks are still generated as white space (html P or BR), causing the last cell to have an extra line. On the other hand, if you keep the #if statements on the same line, there appears to be no way to generate a line break at the start of the output because the parser strips it. So |- will not appear on a new line, and therefore fails to generate a new row (it instead just gets rendered as text). 76.253.0.17 03:12, 26 September 2011 (UTC)
 * Same probleme here. Found any solution? Drhirn 13:03, 8 November 2011 (UTC)
 * Why not just just use html tags? --Subfader 18:14, 8 November 2011 (UTC)
 * Try using the same-line method and placing a invisible character (like <tt>&amp;8201;</tt> or <tt>&amp;#8203;</tt>) at the beginning of the output, before the line break. The innocuous character will then be added to the end of previous cell, and the line break will not be ignored. Note:<tt>&amp;8201;</tt> is a very thin space and <tt>&amp;#8203;</tt> is a zero-width space. Gustronico 17:47, 17 November 2011 (UTC)

#switch
How many parameters can I put into a single #switch?--90.217.236.107 09:59, 22 October 2011 (UTC)

Multiple #if
Is it possible to use the #if function for multiple articles? For example, IF this article AND that article exist, THEN 1; IF this article exists and that NOT, THEN 2; IF this article does NOT exist and that exists, THEN 3; IF both articles do NOT exist, THEN 4. I tried it many times using IF in IF, but it was effectless. Thanks.--Kiril Simeonovski 10:47, 27 December 2011 (UTC)
 * I would use, which will give you values 3, 2, 1 and 0, respectively, for the four cases you described.  Or if the numbers are particularly important, by playing around a bit you should be able to get the exact numbers you want out. Happy ‑ melon 12:16, 27 December 2011 (UTC)
 * Thanks once again. I didn't even imagine it's possible to use "+" sign.--Kiril Simeonovski 13:34, 27 December 2011 (UTC)

Checking if an external link exists
Is there a way to use #if, #ifeq or other ParserFunctions to check if an external URL exists or not (i.e., whether a web page is a dead link)? Smuconlaw 17:59, 15 January 2012 (UTC)
 * No. The wiki parser knows the status of its own pages only by checking its internal database (it does not actually try to load the webpage). It has no way of knowing whether pages exist if they are on unrelated domains. On some wikis, experienced editors occasionally run bots to check the status of external links and edit wikitext containing broken links, but that is unrelated to parser functions. — Richardguk 22:50, 15 January 2012 (UTC)
 * Ah, OK. Thanks. A template at the English Wikipedia relies on an external website, but the managers of that website have launched an updated website which is quite different. I was wondering if the template could be tweaked to check if the old website is still accessible, and, if not, to access the new website instead. Looks like I should wait till the old website has been completely turned off, then rejig the template to link to the new website. — Cheers, SMUconlaw  09:56, 16 January 2012 (UTC)

ifeq match this or that
Is there a way to compare multiple values with a string?

I know I could nest the #ifeq-tags but that results in ugly tag soups.

I could also use #switch but then i have to repeat the output for each. --Subfader (talk) 18:23, 26 March 2012 (UTC)


 * #switch will accept multiple possibilities for each output, so the following would output "yes" for this equal to any of "value1", "value2" or "value3", or output "no" otherwise:
 * See Help:Extension:ParserFunctions for a different example.
 * — Richardguk (talk) 18:41, 26 March 2012 (UTC)
 * — Richardguk (talk) 18:41, 26 March 2012 (UTC)


 * Oh, great :) --Subfader (talk) 06:49, 27 March 2012 (UTC)

No integer division ???
Why is there no integer division for #expr ? There is a modulo operator but no integer division. This is not logical to have one feature and not the other.

We have to subtract 0.5 and then round to 0 digits. Instead div should be the integer division and / should be the decimal division.

--DavidL (talk) 13:32, 15 April 2012 (UTC)

Template:Ifnumber

 * To simplify a complex template, I made a Template:Ifnumber witch detect if an expression is numeric, but else do not generate any error.
 * example : true text
 * Is it a short equivalent, or this template could become a parse function ? Rical (talk) 15:29, 15 April 2012 (UTC)


 * I don't think we need to add another ParserFunction for a feature that can be so easily achieved with a short amount of code using existing functions. Happy ‑ melon 14:11, 17 April 2012 (UTC)

Creating a new line...
I am wondering if any of you guys can help me. I am attempting to use ParserFunctions to create a unit converter for my wiki. The issue is that the "#expr" code is creating a new line after every use. My code is below. Any help would be SOOOOO appreciated! Thanks!!! --Zackmann08 (talk) 22:22, 1 May 2012 (UTC)

The template: " lbs ( kg)"

The use of the template:
 * Weight:
 * Weight:

What it produces: What I WANT it to produce:
 * Weight: "2.2 lbs (1 kg)"
 * Weight: "4.41 lbs (2 kg)"
 * Weight: "2.2 lbs (1 kg)"
 * Weight: "4.41 lbs (2 kg)"

---
 * Hello, you have to make sure that the transcluded part is inline (when you need it to be). This means no Enters in the part that will be transcluded with the template. This can go wrong when you transclude a category with a template. If there is a Enter after the category it will get transcluded. Also, when you save the page starting with a Enter it will not show when you edit it again but it is still there. If you want more layout control we always exactly "tell" the wiki engine what needs to be transcluded. See example that will work below (on MW 1.17.2):

Any Template documentation
When you have a Enter between the category and the it will mess up the result. --Jongfeli (talk) 11:46, 2 May 2012 (UTC)
 * Bla bla 1
 * Bla bla 2
 * Bla bla 3 " lbs ( kg)"


 * THANK YOU SOOOOO MUCH!!!!! That really helped!!! --Zackmann08 (talk) 22:20, 2 May 2012 (UTC)

lenght of a string
Hi, I just want to share parser function to find lenght of a given string.You can find the template here, but it is in Turkish. It is up to 10 characters but you can increase. the size.

Saltinbas (talk) 15:15, 14 May 2012 (UTC)
 * code =

#switch/#ifeq with apostrophes
For example, if you're matching a pagename that contains an apostrophe to the plain text version

the result always comes out to be 'n', oddly.

Anyone know a loop around this? --108.224.95.15 05:50, 25 July 2012 (UTC)
 * Nevermind, replacing the apostrophe with &#39 ; works. --108.224.95.15 05:54, 25 July 2012 (UTC)

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

which is equivalent to:
 * <tt> </tt>

DPL has the advantage that it does not create a link between the target page (page title) and the page containing the query. Using <tt>#ifexist</tt> 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 == into the article if there are some s entered in the wikitext. If there's no no heading and no references/ should be inserted.

I tried different things but none of them work - that means I always get "Heading and stuff" even if there's no ref tag entered in the article:

The docu says "Content inside parser tags (such as nowiki) is temporarily replaced by a unique code" and shows that tags won't work.

Is there a workaround to let be parsed inside the #if?

--Stefahn (talk) 17:38, 9 November 2012 (UTC)

#time: and Daylight Savings
Is there any flag for DST? Is there any intent to add a flag for this in the future if it currently doesn't exist? Thank you. -- ShoeMaker  ( Contributions &bull; Message )   18:30, 9 November 2012 (UTC)