• Welcome to NIWA Community Forums.
 

Color dependent templates

Started by HavocReaper48, January 03, 2011, 08:56:56 PM

Previous topic - Next topic

HavocReaper48

Need a little coding help.

Over at the DKWiki I had an idea of changing the level template color per type of level (water get shades of blue, snow levels silver and white, etc.), and I would like to know how exactly these things are coded.

Toomai

You mean using a #switch statement to select colours based on a word of input?
oeuf

HavocReaper48

Oh, yes. That needs to be added to the Mediawiki?

Toomai

oeuf

SnorlaxMonster

Bulbapedia's location template does a similar thing. It shouldn't be too hard to set up. However, Bulbapedia actually has a whole bunch of color templates which make it easier to synchronize colors.

Example:

style="color:{{#switch:{{{type|}}|forest=green|desert=brown|water=blue|cave=gray|construction site=black|yellow}}"

Alternately, for better customization, you would want to use hex codes.

Moydow

Quote from: Toomai on January 04, 2011, 12:15:13 AM
It might be already there.
It is, check Special:Version. The ParserFunctions extension is needed for it to work.
NIWA Coordinator

HavocReaper48

Checked, and it does have the ParserFunctions.

I did some toying around in My sandbawx but, nothing much yet. Could one of you guys set an example on-wiki?

Either that or the conversion from Pokemon--->Donkey Kong didn't work too well  :P

BrandedOne

This template on Fire Emblem Wiki uses switch statements. Will looking at that help at all?

SnorlaxMonster

#8
Switch is case sensitive. That's your problem. And the thing you are testing seems to be a template rather than a parameter of the template. So it should be {{#switch:{{{1}}}|stuff goes here}} (replace "1" with whatever the parameter's name is) rather than putting a template there (which currently seems to be a copy of a Bulbapedia link template which shouldn't be needed at all). And you are opening the tested thing with {{{ but closing with only }}.

I hope this was clear enough. I can fix the template myself if you want.

HavocReaper48

I got somewhere, I think....

I tried that template BrandedOne and yes it did help.

But still a little out of order... uh, yeah, Snorlax, please help.

Thanks ahead of time!

Maxite

If this template gets finished, may I borrow it? I have some wonderful ideas for a color changing template for my wiki.

HavocReaper48

I'm fairly certain you can "borrow" templates from any wiki as long as you accredit them. So, yes.

SnorlaxMonster

I think I've fixed the code that you had, but I don't know how well the colors themselves match up to the types. However, I've never player any DKC game, so it is possible these seemingly wacky colors are indeed correct.

Currently, water uses #602820 and #a83028, which really don't seem like water colors to me; jungle shares its color with other (which should really be the default, which should be last); forest cave and allies are also all the same color, which is strangely yellow and blue; lastly, your default (which is for some reason separate from other) is a blue which makes it difficult to read the links.

All of this is specifically to do with which colors are used - other than that, your template should switch colors fine.

HavocReaper48

Uh, the font color changed... not really what I wanted  :-\

I mean, take the real Coral Capers article. Like, those rectangles, the ones that say "world", "type", "underwater"... in the infobox are what I wanted colored.

tacopill

#14
i think you are looking to change it to be background-only. To do so, change

Quote
style="color:{{#switch:{{{type|}}|forest=green|desert=brown|water=blue|cave=gray|construction site=black|yellow}};"

to

Quote
style="background-color:{{#switch:{{{type|}}|forest=green|desert=brown|water=blue|cave=gray|construction site=black|yellow}};"

If you wish to do text color and background color, add both style-information to style="" and separate them by a semi-colon.

Quote
style="background-color:{{#switch:{{{type|}}|forest=green|desert=brown|water=blue|cave=gray|construction site=black|yellow}};color:{{#switch:{{{type|}}|forest=green|desert=brown|water=blue|cave=gray|construction site=black|yellow}};"

(Note: Background: also works for the background color.)

also, a template for the styles may help. This way, you can change the template once, and it changes every location it is used.







HavocReaper48

Uh, when I did it, only yellow showed, and when I removed the yellow part the template reverted to white background.

Is it possible to just borrow the Bulbapedia coding and redesign it?

Also, if I missed something taco you're free to edit my tests subpage and see if you can figure it out.

Tina

There's something similar to this that I use on WikiBound-- although instead of being directly programmed into the template, it's a separate template in itself, and can be used for pretty much anything.

It's here and it should be fairly straightforward, I think. You just put it in the color field (like style="background: #{{lightcolor|locations}}") and it's a bit less of a hassle than having to individually program every template.
WikiBound Editor-in-Chief

tacopill

ok, i've fixed the template and the infobox.

What was wrong was the style="blah blah blah" was in both the infobox and the template(s), which sort confused mediawiki and ignored it complete. Relevent edit.

Also, remember that variables and values are case-sensitive. So, i recommend adding lc: to force the values to be lower-case.







SnorlaxMonster

The colors themselves switch alright, but when I saw the colorscheme for water, my instant reaction was "ARGH, MY EYES!" The blue background is too bright and makes it near impossible to read the text.

tacopill

yea..... we need an elite squadron of color-choosers to go in and help them come up with a color scheme. 


:laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: