# Help talk:Extension:ParserFunctions/2009

## #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 {{templ|begin}} and a different one at {{templ|end}}. 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:

{{#switch:
|1=1 foo
|2=2 foo
|3=3 foo
|1
|2=1+2 foo
|1
|3=1+3 foo
}}


--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:
{{#switch: {{{input}}}
| foo = You entered 'foo'
| bar = You entered 'bar'
| baz
| quok = You entered either 'baz' or 'quok'
}}

Will work perfectly. Happymelon 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 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? Happymelon 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

{{#if:{{age in days|2009|1|20}}|Bush|Obama}}

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:
{{#ifexpr: {{#time:U}} > {{#time:U| January 20 2009}}|Obama|Bush}}
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?

1. if:|[[Image:{{{Logo}}}|130px|]]
well, this:
• {{#if:1|[[Image:Wiki.png|30px|link=]]}} >
• {{#if:|[[Image:Wiki.png|30px|link=]]}} >
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 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:

{{#if: {{{room}}} |
<tr>
<td></td>
<td></td>
<th>
Room {{{room}}}
</th>
<td></td>
<td></td>
</tr>
|  }}


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.

## 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:

<math alt="Upper: {{{upper}}} / Lower: {{{lower}}}{{#if: {{{total|}}} |, Total teeth = {{{total}}}|}}">\tfrac{ {{{upper}}}}{ {{{lower}}}}{{#if: {{{total|}}} | \times 2 = {{{total}}}|}}[/itex]

This yields the error: "Failed to parse (lexing error): \tfrac{ {{{upper}}}}{ {{{lower}}}}{{#if: {{{total|}}} | \times 2 = {{{total}}}|}}"

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)