Forum:Would this work in a template

Would this code work in a template to switch if any of the specified articles are present?

{{#switch:{{{Species}}}|Dragon|Varik|Raptor|Wyvern=

 Helloher    (Death is not my phone number)  20:18, July 19, 2010 (UTC)
 * No, unfortunately the code would have to be:

{{#switch:{{{Species}}}|Dragon= Foo|Varik= Foo|Raptor= Foo|Wyvern= Foo -- Random Time  21:05, July 19, 2010 (UTC)


 * (edit conflict) - That does not look right from when i've seen it used. But i cannot remember were it was to look at the code it was in, but i think it was used to test which namspace a page was in & then display a different message. So in your application it would not work as more than one could be true at once, so which would it chose ? #ifexist may be more suitable ? but i'm not totally sure what you are looking to do with it.


 * Here is the help page at mediaWiki.org about the switch function and other parser functions. - BulldozerD11 21:09, July 19, 2010 (UTC)


 * Please explain exactly what you are trying to do. Bad wikicode fragments without context will just lead to alot of round-about guessing. -- Fandyllic  (talk &middot; contr) 5:54 PM PST 19 Jul 2010


 * This is the template:

http://gametechmodsstorytime.wikia.com/wiki/Template:Character

What I am looking for is that, if the Species entered is Dragon, Varik, Wyvern or Raptor, then it would disable the parameter hair color and enable scale color instead.  Helloher    (Death is not my phone number)  06:08, July 20, 2010 (UTC)


 * It should be possible, but I think you're making it overly complicated. Why don't you use the #if: parser function for those parameters like you did on other items? Then if it'a dragon, etc. simply don't use the hair parameter --Bram{{sup|Talk/IGW}} 11:36, July 20, 2010 (UTC)


 * Your infobox construction method is different from the one i use and as its full of switch bits already so looks like you borrowed it from another wiki !! (if so it is useful to know were from and it should be credited Under CC by SA anyway if sourced from another wiki). I cannot try it out as you have locked it as well after asking for help !! Wikipages should not be protected from editing unless subject to vandalism or they are the wikis policy pages. I've wasted enough time looking for a solution now to bother creating seperate test examples instead of just trying to fix your template.


 * BTW - I think the wiki link brackets in the #switch statement are probably breaking it if it doesent work as you have it. As Bram says it looks over complicated.

- BulldozerD11 12:32, July 20, 2010 (UTC)
 * I wanted to test something out, so I created Template:Character/Sandbox for that purpose (since the original one is locked). The Scale color part now looks like this:

{{#if:{{#ifeq:{{{Species}}}|Dragon|Foo|}}{{#ifeq:{{{Species}}}|Varik|Foo|}}{{#ifeq:{{{Species}}}|Raptor|Foo|}}{{#ifeq:{{{Species}}}|Wyvern|Foo|}}| {{!}} class="infobox_column_left" {{!}} Scale Color {{!}} class="infobox_column_right" {{!}} {{{Scales|N/A}}} {{!}}- style="border:1px solid #{{Color|Border}};" }}
 * which makes it appear only if Dragon, Varik, Raptor or Wyvern is filled out at Species. Unfortunately, I can't figure out a way to make this work the other way around (see what I've tried at the Character/Sandbox page). It would be easy if there only were like 10 species, then you could do the same thing for the Hair color bit with the other six species. Maybe someone else has an idea. --Bram{{sup|Talk/IGW}} 12:42, July 20, 2010 (UTC)


 * So would that work now?  Helloher    (Death is not my phone number)  13:14, July 20, 2010 (UTC)
 * Not yet. I figured out a way for the 'scale' bit, but there has to be a way for the 'hair' bit also. Bram{{sup|Talk/IGW}} 13:21, July 20, 2010 (UTC)


 * I think I figured out a way:

{{#if:{{#switch:{{{Species}}}|Dragon=Foo|Varik=Foo|Raptor=Foo|Wyvern=Foo|}}| {{!}} class="infobox_column_left" {{!}} Scale Color {{!}} class="infobox_column_right" {{!}} {{{Scales|N/A}}} {{!}}- style="border:1px solid #{{Color|Border}};" }} {{#if:{{#switch:{{{Species}}}|Dragon=|Varik=|Raptor=|Wyvern=|Bar}}| {{!}} class="infobox_column_left" {{!}} Hair Color {{!}} class="infobox_column_right" {{!}} {{{Hair|Unknown}}} {{!}}- style="border:1px solid #{{Color|Border}};" }}


 * I left a working template at Template:Character/Sandbox (so you can copy it from there as well) and two filled out examples at the sandbox. I just noticed it actually should respond on  Dragon  etc. with link brackets and not on Dragon since that's the way the Species parameter should be filled out, but I think you can change that yourself. -Bram{{sup|Talk/IGW}} 13:41, July 20, 2010 (UTC)

Thanks so much. It's really helpful.  Helloher    (Death is not my phone number)  14:52, July 20, 2010 (UTC)


 * Just as a remark,  is unnecessarily complicated.   does exactly the same. See mw:Help:Extension:ParserFunctions. -- Porter21 {{sup|(talk)}} 14:59, July 20, 2010 (UTC)
 * Thanks for pointing that out. It also doesn't need the final pipe character for the default output to be empty? Or is the 'default' output always empty if it isn't specified? --Bram{{sup|Talk/IGW}} 15:11, July 20, 2010 (UTC)
 * Edit: never mind, already found it in the manual: If the default parameter is omitted and no match is made, no result is returned --Bram{{sup|Talk/IGW}} 15:15, July 20, 2010 (UTC)