NIWA Community Forums

NIWA Community => NIWA Discussion => Topic started by: HavocReaper48 on January 03, 2011, 08:56:56 PM

Title: Color dependent templates
Post by: HavocReaper48 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.
Title: Re: Color dependent templates
Post by: Toomai on January 03, 2011, 11:15:51 PM
You mean using a #switch statement (http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#.23switch) to select colours based on a word of input?
Title: Re: Color dependent templates
Post by: HavocReaper48 on January 03, 2011, 11:29:19 PM
Oh, yes. That needs to be added to the Mediawiki?
Title: Re: Color dependent templates
Post by: Toomai on January 04, 2011, 12:15:13 AM
It might be already there.
Title: Re: Color dependent templates
Post by: SnorlaxMonster 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.
Title: Re: Color dependent templates
Post by: Moydow on January 04, 2011, 12:58:03 AM
Quote from: Toomai on January 04, 2011, 12:15:13 AM
It might be already there.
It is, check Special:Version (http://www.donkeykongwiki.com/Special:Version). The ParserFunctions extension is needed for it to work.
Title: Re: Color dependent templates
Post by: HavocReaper48 on January 04, 2011, 03:05:30 AM
Checked, and it does have the ParserFunctions.

I did some toying around in My sandbawx (http://www.donkeykongwiki.com/User:HavocReaper48/Tests) 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
Title: Re: Color dependent templates
Post by: BrandedOne on January 04, 2011, 04:24:47 AM
This template (http://fireemblemwiki.info/Template:Notable_Units) on Fire Emblem Wiki uses switch statements. Will looking at that help at all?
Title: Re: Color dependent templates
Post by: SnorlaxMonster 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.
Title: Re: Color dependent templates
Post by: HavocReaper48 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!
Title: Re: Color dependent templates
Post by: Maxite 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.
Title: Re: Color dependent templates
Post by: HavocReaper48 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.
Title: Re: Color dependent templates
Post by: SnorlaxMonster 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.
Title: Re: Color dependent templates
Post by: HavocReaper48 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 (http://www.donkeykongwiki.com/Coral_Capers) article. Like, those rectangles, the ones that say "world", "type", "underwater"... in the infobox are what I wanted colored.
Title: Re: Color dependent templates
Post by: tacopill 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.
Title: Re: Color dependent templates
Post by: HavocReaper48 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.
Title: Re: Color dependent templates
Post by: Tina 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 (http://wikibound.info/Template:Lightcolor) 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.
Title: Re: Color dependent templates
Post by: tacopill 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 (http://www.donkeykongwiki.com/index.php?title=User:HavocReaper48/Tests/Loc&curid=4283&diff=19131&oldid=19130).

Also, remember that variables and values are case-sensitive (http://www.donkeykongwiki.com/index.php?title=User:HavocReaper48/Tests&curid=4282&diff=19135&oldid=19122). So, i recommend adding lc: (http://www.donkeykongwiki.com/index.php?title=Template:Type&action=historysubmit&diff=19136&oldid=19134) to force the values to be lower-case.
Title: Re: Color dependent templates
Post by: SnorlaxMonster 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.
Title: Re: Color dependent templates
Post by: tacopill 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:





Title: Re: Color dependent templates
Post by: SuperAlpaca on January 11, 2011, 03:05:14 PM
Quote from: tacopill 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:







That would actually be nice.
Title: Re: Color dependent templates
Post by: HavocReaper48 on January 12, 2011, 05:24:26 PM
Uh, now the template's not working with temple and jungle levels, which I added  :-\ I think I'm better off adding a subtemplate, "Template:Level/water", "Template:Level/jungle", etc. and adding that to levels.

But on a side note, whatever coding actually worked can be borrowed to whatever wiki needs it.
Title: Re: Color dependent templates
Post by: tacopill on January 12, 2011, 09:17:21 PM
I'm sorry the suggestion(s) didn't work out for you, but am happy you found one that does work for you. Good luck with it.
Title: Re: Color dependent templates
Post by: SuperAlpaca on January 13, 2011, 09:40:19 PM
Congrats on finding a working template. I enjoy borrowing templates myself, which is how I create all templates. I usually use other templates I made if it is similar, though.
Title: Re: Color dependent templates
Post by: SnorlaxMonster on January 14, 2011, 04:12:08 AM
I like the new colorscheme. It's much softer and easier to read than the previous one.
Title: Re: Color dependent templates
Post by: HavocReaper48 on January 19, 2011, 11:32:33 PM
Yeah, it's what I wanted to do initially.

If anyone can help come up with some color schemes or just give feedback on existing ones that would be great.