Wikia

WoWWiki

Give templates different use choices: how?

101,547pages on
this wiki

Forum page

Forums: Index WoWWiki technical Give templates different use choices: how?

I didn't know how to ask this, but I think you'll get what I'm speaking about with a simple example:

{{RaceIcon|<<race>>|<<gender>>}}

As you see, this template has some folders that make the template show different things depending on the value they have.

My question is: How do I write the code for defining those folders?

What I want to make is an userbox that, depending on the number you put, changes a word in the text and shows a different image. I could make different templates for each case, but they are many and I think this could be a better option, and also easier to understand by the users.

I suspect it's related with the type of coding; if I'm right, just translate me the ways of putting "if"s and the basic commands. I know enough programming to get the code idea, but I don't know anything about the language.

It's something I always wanted to know, and I think this could be the perfect chance to get to know how to, and be able to build better ones in the future Tongueout.--Lon-ami (talk) 19:46, October 11, 2009 (UTC)

See mw:Help:Extension:ParserFunctions. --PcjWoWWiki admin (TDrop me a line!C62,301 contributions and counting) 19:59, October 11, 2009 (UTC)
Thanks! That was just what I needed. I'll give it a read, and try to build the template. I'll post my results here later Winky.--Lon-ami (talk) 17:39, October 12, 2009 (UTC)

Switching with values between two numbersEdit

Ok, so I got to understand this, more or less.

Now, I only don't know how to, instead of this:

{{#switch:{{lc:{{{1}}}}}
|1=AAA
|2=AAA
|3=AAA
|4=AAA
|5=BBB
|6=BBB
|7=BBB
|8=BBB}}

Make something like this (rough):

{{#switch:{{lc:{{{1}}}}}
|1 to 4=AAA
|5 to 8=BBB}}

I want to work with high values (1-50, 50-100, 100-250, 250-500, 500-1000, 1000-2500...) and I don't know how to build those ranges :S. I'm sure it's pretty simple, but I fail to find the solution.

I need it for 2 things:

  • Display a text depending on number range.
  • Display a image depending on number range (I don't know if images need a special code or something for working properly).

Thanks!--Lon-ami (talk) 18:44, October 26, 2009 (UTC)

You may want to use #ifexpr rather than #switch in this case. Or maybe you can combine the two, but I've never done it. --Gengar orange 22x22Beware the sneaky smile! Fandyllic (talk · contr) 10:33 PM PST 26 Oct 2009
I think I'll just go for "nested" (dunno if it's well said) ifs, something like this:
{{#ifexpr: X > 0 | {{#ifexpr: Y > 0 | both x and y are bigger than 0 | only x is biger than 0}} | x isn't bigger than 0}}
This checks if x is bigger than 0, and if it's true, then it checks if y is bigger than 0. Repeat this proccess, let's say, 20 times, and there you have, the perfect result. Now I only need to search the proper images and it'll be done Grin.--Lon-ami (talk) 21:11, October 31, 2009 (UTC)
Damn, I knew this was too easy.
So, I have a new problem: I don't know how to introduce variables into the ifexpr. I try {{{1}}}, but it fails.
Any ideas?--Lon-ami (talk) 21:26, October 31, 2009 (UTC)
I think it has something to do with this:
[1]
Will check and ask again tomorrow if I can't solve this up :S.--Lon-ami (talk) 21:58, October 31, 2009 (UTC)
I suspect #ifexpr is not supported on WoWWiki. I tried to get it to work on a test template, but it kept giving me an error. I also noticed our version of ParserFunctions is 1.1.1, but the one running on Mediawiki-logo-18x24 mediawiki.org is 1.3.0.
You could try using: {{#ifeq: {{#expr: expression }} | 0 | value if false | value if true }}
It is supposed to be the equivalent. I made a test range checking template at User:Fandyllic/rangetest as an example to try out some range checking.
  • {{:User:Fandyllic/rangetest|0}}
    • Output: Number is 0 or negative
  • {{:User:Fandyllic/rangetest|3}}
    • Output: Number is 1 to 5
  • {{:User:Fandyllic/rangetest|8}}
    • Output: Number is 6 to 10
  • {{:User:Fandyllic/rangetest|15}}
    • Output: Number is greater than 10
--Gengar orange 22x22Beware the sneaky smile! Fandyllic (talk · contr) 6:01 AM PST 1 Nov 2009
WHoA, thanks a lot. So it was that, damn, and me trying and trying with the damn ifexpr. It doesn't matter, it works now, an d that's what matters :P.
Anyway, just as a curiosity, what is that | 0 | for?
That's all. I'm gonna check if it works properly with images now, and will return else to show the finished template or more doubts Smiley.--Lon-ami (talk) 15:28, November 3, 2009 (UTC)
| 0 | basically means "false".
You could use | 1 | instead, I believe, and then the wikicode would just be slightly different:
{{#ifeq: {{#expr: expression }} | 1 | value if true | value if false }}
--Gengar orange 22x22Beware the sneaky smile! Fandyllic (talk · contr) 6:38 PM PST 3 Nov 2009
Yeah, it seems the true and false folders switch between them. Anyway, implemented it with anything (guess it reads as default 1) and everything worked fine. This was just an experiment to try these functions, but I'm definitely going to apply these anywhere I see it can be applied Tongueout:
Spell holy elunesgrace This user is ranked Elune with 5826 posts at Scrolls of Lore!
Again, thanks for the help ;).--Lon-ami (talk) 20:45, November 3, 2009 (UTC)

Around Wikia's network

Random Wiki