Author Topic: Color dependent templates  (Read 14800 times)

Offline HavocReaper48

  • The Falcon Punch Master
  • Donkey Kong Wiki Staff
  • ***
  • Posts: 386
  • Gender: Male
  • Orly?
    • View Profile
Color dependent templates
« on: January 03, 2011, 08:56:56 PM »
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.

Offline Toomai

  • SmashWiki Staff
  • ***
  • Posts: 106
  • Gender: Male
  • Smash & Learn
    • View Profile
    • SmashWiki
Re: Color dependent templates
« Reply #1 on: January 03, 2011, 11:15:51 PM »
You mean using a #switch statement to select colours based on a word of input?
oeuf

Offline HavocReaper48

  • The Falcon Punch Master
  • Donkey Kong Wiki Staff
  • ***
  • Posts: 386
  • Gender: Male
  • Orly?
    • View Profile
Re: Color dependent templates
« Reply #2 on: January 03, 2011, 11:29:19 PM »
Oh, yes. That needs to be added to the Mediawiki?

Offline Toomai

  • SmashWiki Staff
  • ***
  • Posts: 106
  • Gender: Male
  • Smash & Learn
    • View Profile
    • SmashWiki
Re: Color dependent templates
« Reply #3 on: January 04, 2011, 12:15:13 AM »
It might be already there.
oeuf

Offline SnorlaxMonster

  • Bulbapedia Staff
  • ***
  • Posts: 485
  • Gender: Male
  • Bulbapedia bureaucrat, Zelda Wiki administrator
    • View Profile
Re: Color dependent templates
« Reply #4 on: January 04, 2011, 12:50:25 AM »
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.

Offline Moydow

  • NIWA Coordinator
  • Forum Administrator
  • *****
  • Posts: 483
    • View Profile
    • Fire Emblem Wiki
Re: Color dependent templates
« Reply #5 on: January 04, 2011, 12:58:03 AM »
It might be already there.
It is, check Special:Version. The ParserFunctions extension is needed for it to work.
NIWA Coordinator

Offline HavocReaper48

  • The Falcon Punch Master
  • Donkey Kong Wiki Staff
  • ***
  • Posts: 386
  • Gender: Male
  • Orly?
    • View Profile
Re: Color dependent templates
« Reply #6 on: January 04, 2011, 03:05:30 AM »
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

Offline BrandedOne

  • Fire Emblem Wiki Staff
  • ***
  • Posts: 180
  • Gender: Male
    • View Profile
Re: Color dependent templates
« Reply #7 on: January 04, 2011, 04:24:47 AM »
This template on Fire Emblem Wiki uses switch statements. Will looking at that help at all?

Offline SnorlaxMonster

  • Bulbapedia Staff
  • ***
  • Posts: 485
  • Gender: Male
  • Bulbapedia bureaucrat, Zelda Wiki administrator
    • View Profile
Re: Color dependent templates
« Reply #8 on: January 04, 2011, 05:06:10 AM »
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.
« Last Edit: January 04, 2011, 05:12:10 AM by SnorlaxMonster »

Offline HavocReaper48

  • The Falcon Punch Master
  • Donkey Kong Wiki Staff
  • ***
  • Posts: 386
  • Gender: Male
  • Orly?
    • View Profile
Re: Color dependent templates
« Reply #9 on: January 04, 2011, 08:54:21 PM »
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!

Offline Maxite

  • Icaruspedia Staff
  • ***
  • Posts: 681
  • Gender: Male
  • Otaku Nut
    • View Profile
    • OtakuDeus
Re: Color dependent templates
« Reply #10 on: January 04, 2011, 10:20:57 PM »
If this template gets finished, may I borrow it? I have some wonderful ideas for a color changing template for my wiki.

Offline HavocReaper48

  • The Falcon Punch Master
  • Donkey Kong Wiki Staff
  • ***
  • Posts: 386
  • Gender: Male
  • Orly?
    • View Profile
Re: Color dependent templates
« Reply #11 on: January 04, 2011, 10:57:31 PM »
I'm fairly certain you can "borrow" templates from any wiki as long as you accredit them. So, yes.

Offline SnorlaxMonster

  • Bulbapedia Staff
  • ***
  • Posts: 485
  • Gender: Male
  • Bulbapedia bureaucrat, Zelda Wiki administrator
    • View Profile
Re: Color dependent templates
« Reply #12 on: January 05, 2011, 05:13:34 AM »
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.

Offline HavocReaper48

  • The Falcon Punch Master
  • Donkey Kong Wiki Staff
  • ***
  • Posts: 386
  • Gender: Male
  • Orly?
    • View Profile
Re: Color dependent templates
« Reply #13 on: January 05, 2011, 06:10:20 AM »
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.

Offline tacopill

  • Lylat Wiki Staff
  • ***
  • Posts: 3128
    • View Profile
    • csanimefan
Re: Color dependent templates
« Reply #14 on: January 06, 2011, 07:35:23 PM »
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.
« Last Edit: January 06, 2011, 07:38:03 PM by tacopill »







Offline HavocReaper48

  • The Falcon Punch Master
  • Donkey Kong Wiki Staff
  • ***
  • Posts: 386
  • Gender: Male
  • Orly?
    • View Profile
Re: Color dependent templates
« Reply #15 on: January 06, 2011, 08:41:11 PM »
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.

Offline Tina

  • WikiBound Staff
  • ***
  • Posts: 320
  • Gender: Female
    • View Profile
    • WikiBound
Re: Color dependent templates
« Reply #16 on: January 06, 2011, 09:24:54 PM »
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

Offline tacopill

  • Lylat Wiki Staff
  • ***
  • Posts: 3128
    • View Profile
    • csanimefan
Re: Color dependent templates
« Reply #17 on: January 07, 2011, 11:04:39 PM »
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.







Offline SnorlaxMonster

  • Bulbapedia Staff
  • ***
  • Posts: 485
  • Gender: Male
  • Bulbapedia bureaucrat, Zelda Wiki administrator
    • View Profile
Re: Color dependent templates
« Reply #18 on: January 08, 2011, 01:57:42 PM »
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.

Offline tacopill

  • Lylat Wiki Staff
  • ***
  • Posts: 3128
    • View Profile
    • csanimefan
Re: Color dependent templates
« Reply #19 on: January 08, 2011, 09:15:10 PM »
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: