Template talk:By color

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Considerations[edit]

(Discussion moved from user talk page Michael Barera)

Hi Michael, you do useful work with these templates, expanding them and making them universally useable. I know they are grown in a long time, they are transcluded very often and there is no urgent need to simplify them. Another thing would be if they were new designed and created. Then I had introduced only one parameter, no matter whether capitalized or not, and used it with ucfirst and lcfirst for the categories. Of course this would have caused some bloating of the template's code, which could have been avoided by a clever subtemplate structure (or requesting the lower case name only, and capitalizing it once for the main category). The present template is straight, simple and easy, it is just a little bit tedious that it needs the name twice. Regards, sarang사랑 06:54, 15 May 2015 (UTC)[reply]

Thanks for dropping me a line, Sarang. The biggest advantage of {{By color}} over {{Navigation by color}} is that the former recognizes categories that exist and automatically includes them in the template, while the latter must be hand-coded for each individual use and (apparently) necessitates the use of a subtemplate, "Template:Navigation [Name of category] by color". Perhaps there is no urgent need to simplify and increase the usability of the templates, but I certainly think that the use of {{By color}} constitutes an improvement.
Your point about {{By color}} requiring both the upper-case and lower-case terms is well taken. Please feel free to edit the code of {{By color}}, using a subtemplate or whatever other approach you think best, to allow it to work effectively with just one term. I would advise that if you make said changes, you make the one term the capitalized term and then that way the template could simply ignore the secondary lower-case term. Michael Barera (talk) 14:41, 15 May 2015 (UTC)[reply]

Hi again. As I said there is no need to alter something of the existing template; only if I had to write a new one I would have selected another strategy than requesting the name twice. I gave the template's history a short look and saw your useful improvements.
Besides, your suggestion would use just once the capitalized name but many times the lc or lcfirst would become necessary (when I counted right there are 34 colors, that needs 68 lcs). No, I won't change it without further reason. Everything can be done in different ways, for many things exist a better solution, but there are many requests of more urgency to do. It may just kept in mind (or on the template's talk page?) that a possibly redesigned future template can do with one parameter. sarang사랑 15:39, 15 May 2015 (UTC)[reply]

Thanks again, Sarang. As you've observed, this isn't a perfect solution, but I do think that it is an improvement. All the best! Michael Barera (talk) 16:51, 15 May 2015 (UTC)[reply]
@Sarang: I actually discovered a couple of categories that use different strings for the two fields in the {{By color}} / {{Life by color}} templates: for instance, {{Navigation Flora of Hong Kong by color}} used both "Flora of Hong Kong" and "flowers in Hong Kong", so I think it is a good thing my template(s) take two fields and are thus able to accommodate these situations without any extra modification or the need for a separate template. Michael Barera (talk) 17:52, 15 May 2015 (UTC)[reply]

OK, that's fine; I just meant for the standard usage (when both names are the same only different by the case of the first letter) one parameter would be enough. I would have even searched whether it was reasonable to enable its use without any parameter, setting defaults from the category name. Specifying both names is much easier for the template, and better visible for the user.
The rule "keep it easy" can lead into two diverging directions: a sophistic template is easy to use for the experineced user, but not for the novice, and needs more difficult template code and more detailed description. The present solution needs always the double parameter but has a simple structure easy to modify. I will not keep you away from your work any longer, thank you for the discussion. sarang사랑 06:08, 16 May 2015 (UTC)[reply]

Example[edit]

The following template code shows one of many possible solutions. It works with both parameters, with only parameter one and without any parameter. Transclusion with only parameter two is not served.

When no parameter at all is provided the template checks the category. Because at the moment no useful string operation module for that purpose is available, the Module:String is used; that is not a good solution, it must be performed multiple times. Before changing the template, a module should be created that can parse the tokens of the category names: when the category name ends with "by color" only the preceding string is needed, otherwise the string after the first space.
When passing that string to a subtemplate, the repetitive invocation of the module can be avoided. The switch check for all color names is then also not needed.
In this example the present {{By color}} is symbolized by the "ByCol".

{{#if:{{{1|}}}<!--                     when parm1 is provided, 
-->|{{#if:{{{2|}}}<!--                 check parm2:
-->|{{tle|t=ByCol|{{{1}}}|{{{2}}}}}<!-- when parm1 and parm2 is specified, take it as it is
-->|{{tle|t=ByCol|{{ucfirst:{{{1}}}}}|{{lcfirst:{{{1}}}}}}}}}<!-- when only parm1, use it twice

             otherwise without any parm it must be constructed from the PAGENAME
-->|{{#switch:{{Trim|{{padleft:|{{#invoke:String|find|{{PAGENAME}}| |1|1}}|{{PAGENAME}}}}}}
|Amber
|Beige
|Black
|Blue
|Brown
|Coral
|Cream
|Crimson
|Cyan
|Golden
|Gold
|Gray
|Green
|Grey
|Hazel
|Lilac
|Magenta
|Maroon
|Mauve
|Olive
|Orange
|Pink
|Purple
|Red
|Salmon
|Silver-colored
|Silver
|Teal
|Turquoise
|Violet
|White
|Yellow
|Colorful
|Rainbow
|Bicolor
|Tricolor
|Colorless
|Transparent={{tle|t=ByCol<!-- the category name is <Color> <item> -->
|{{ucfirst:{{trim|{{#invoke:String|sub|{{PAGENAME}}|{{#invoke:String|find|{{PAGENAME}}| |1|1}}}}}}}}
|{{lcfirst:{{trim|{{#invoke:String|sub|{{PAGENAME}}|{{#invoke:String|find|{{PAGENAME}}| |1|1}}}}}}}}}}<!--

-->|#default={{tle|t=ByCol<!-- the category name is <Item> "by color" -->
|{{ucfirst:{{trim|{{padleft:|{{#invoke:String|find|{{PAGENAME}}| by color}}|{{PAGENAME}}}}}}}}
|{{lcfirst:{{trim|{{padleft:|{{#invoke:String|find|{{PAGENAME}}| by color}}|{{PAGENAME}}}}}}}}}}}}}}

This code has been tested, it works fine (but not very server-friendly). sarang사랑 17:50, 19 May 2015 (UTC)[reply]

Lilac[edit]

Forgot to mention this in my edit summary, but I think the previous lilac was copied from a some-flowers-by-colour template, and so was originally adapted to show a more natural shade more likely to appear in plants. I changed it to a brighter one to provide a shade that's easier to tell apart with all the other colours used in this template. --Pitke (talk) 10:46, 29 May 2015 (UTC)[reply]

Redirected categories[edit]

Can someone make it so that redirected categories are excluded from the template? (e.g. in Category:Chasubles by color Tom-L (talk) 10:00, 23 April 2016 (UTC)[reply]

@Tom-L and Michael Barera: I thought about that since Category:Logos by color shows both Category:Gray logos, and Category:Grey logos. Grey logos is redirecting to Gray logos. Thinking about the technical possibilities, the only way I am aware of to check if a category is redirected, is to count the pages (including subcategories and files) within a category. So this is my solution:
<span style="white-space:nowrap">{{#ifexist: Category:Grey {{{2}}} | {{#ifexpr: {{PAGESINCAT:Grey {{{2}}}}}>0|{{ColorSample|grey}} [[:Category:Grey {{{2}}}|Grey]] &nbsp;|}}|}}</span>
If a category exists, it is checked for the number of pages within it. If there is at least one page, the Category is displayed. I don't want to overload the parsing any more, so one can consider to only add this check to colors which are identical (Gray/Grey, Gold/Golden, Silver/Silver-colored), hence the possibility to have a redirecting category is high(er). How do you think about that? --Badgon (talk) 21:50, 19 May 2016 (UTC)[reply]
That sounds good to me, but I must admit I am out of my league on this topic and recuse myself from this discussion. Thanks for all your work on Commons, and happy editing! Michael Barera (talk) 12:34, 20 May 2016 (UTC)[reply]

Cream doesn't work[edit]

see Category:Cream buses

should change in the source text "Cream (color)" to "Cream"? --Atamari (talk) 08:49, 28 July 2016 (UTC)[reply]

I removed the "color" part and now it works as intended. De728631 (talk) 19:45, 29 September 2021 (UTC)[reply]

"LangSwitch Error: no default"[edit]

As I see at Category:Sunsets by color, there is an error: "LangSwitch Error: no default". I click Category:Sky by color and see the same. Please fix. --ssr (talk) 11:26, 5 June 2018 (UTC)[reply]

Better link[edit]

The navigational tokens should link not only from the color name but also from the color sample box.
An alternate version of the Template:By color can do that, it uses the subtemplate By color/col; it's not yet tested for all cases.

<div class="catlinks" style="line-height:1.6;text-align:center">
<div style="padding:0.1em">[[:Category:{{{1}}} by {{{colour|color}}}|{{LangSwitch|lang={{#if:{{{lang|}}}|{{{lang|}}}|{{int:Lang}}}}
|bn={{{colour|{{label|Q1075|link=-}}}}} {{By|mc=y}} {{{1}}}
|default ={{{1}}} {{By|mc=y}} {{{colour|{{label|Q1075|link=-}}}}}
}}]]</div>
<div style="padding:0.1em;font-size:90%"><!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Amber    |FFBF00|679355}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Apricot  |FBCEB1|1324818}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Beige    |F5F5DC|843607}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Black    |000000|23445}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Blue     |2337F7|1088}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Bordeaux |571C20|19888391}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Brown    |80583C|47071}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Burgundy |900020|797446}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Celadon  |ACE1AF|2541418}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Chartreuse|7FFF00|1153119}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Coral    |F5757F|2411228}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Cream    |FFFDD0|2730433}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Cream (color)|FFFDD0|2730433}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Crimson  |DC143C|303826}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Cyan     |53F1F1|180778}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Gold     |FFD700|208045}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Golden   |FFD700|208045}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Gray     |808080|42519}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Grey     |808080|42519}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Green    |18A814|3133}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Hazel    |5F6401|17122740}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Khaki    |C3B091|650770}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Lilac    |DBBFF9|2294993}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Magenta  |E83BE8|3276756}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Magenta (colour)|E83BE8|3276756}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Maroon   |800000|10859033}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Mauve    |E0B0FF|604079}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Navy     |000080|5975887}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Olive    |808000|864152}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Orange   |FFA500|39338}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Orange (colour)|FFA500|39338}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Pink     |FFC0BC|429220}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Purple   |8A1799|3257809}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Red      |F00|3142}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Salmon   |FA8072|2015138}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Salmon (color)|FA8072|2015138}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Sepia    |704214|767608}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Silver   |C0C0C0|317802}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Silver-colored|C0C0C0|317802}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Tan      |D2B48C|1670336}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Teal     |008080|1078214}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Turquoise|28C6B5|5960345}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Vermilion|E34234|737438}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Violet   |6422D3|428124}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|White    |FFF|23444}}<!--
-->{{By color/col|{{{2|{{lcfirst:{{{1}}}}}}}}|Yellow   |F1F14B|943}}<!--
--></div>
<div style="font-size:90%"><!--
  -->{{#ifexist: Category:Bicolor  {{{2}}}|<span style="padding:0 .2em;white-space:nowrap"><span style="border:1px solid #000;padding:0 .3em">'''2'''</span> [[:Category:Bicolor  {{{2}}}|Bicolor  ]]</span>}}<!--
  -->{{#ifexist: Category:Tricolor {{{2}}}|<span style="padding:0 .2em;white-space:nowrap"><span style="border:1px solid #000;padding:0 .3em">'''3'''</span> [[:Category:Tricolor {{{2}}}|Tricolor ]]</span>}}<!--
  
  -->{{#ifexist: Category:Colorful   {{{2}}}|<span style="padding:0 .2em;white-space:nowrap">[[File:Rainbow icon.svg|18px]] [[:Category:Colorful {{{2}}}|{{label|Q21157531|link=-|capitalization=ucfirst}}           ]]<!--
  -->{{#ifexist: Category:Rainbow    {{{2}}}|                                                                             / [[:Category:Rainbow  {{{2}}}|           {{label|Q21157531|link=-|capitalization=ucfirst}} ]]}}</span>
   | {{#ifexist: Category:Rainbow    {{{2}}}|<span style="padding:0 .2em;white-space:nowrap">[[File:Rainbow icon.svg|18px]] [[:Category:Rainbow  {{{2}}}|{{label|Q21157531|link=-|capitalization=ucfirst}} ]]</span>}}}}<!--

  -->{{#ifexist: Category:Colorless   {{{2}}}|<span style="padding:0 .2em;white-space:nowrap">{{ColorSample|transparent}}    [[:Category:Colorless   {{{2}}}|{{label|Q32848124|link=-|capitalization=ucfirst}}               ]]<!--
  -->{{#ifexist: Category:Transparent {{{2}}}|                                                                             / [[:Category:Transparent {{{2}}}|            {{label|Q487623|link=-|capitalization=ucfirst}} ]]}}</span>
   | {{#ifexist: Category:Transparent {{{2}}}|<span style="padding:0 .2em;white-space:nowrap">{{ColorSample|transparent}}    [[:Category:Transparent {{{2}}}|{{label|Q32848124|link=-|capitalization=ucfirst}} / {{label|Q487623|link=-|capitalization=ucfirst}} ]]</span>}}}}<!--

--></div>
</div><noinclude>
{{Documentation}}
[[Category:By color navigational templates| ]]
</noinclude>

-- sarang사랑 14:43, 14 July 2018 (UTC)[reply]

Not working properly[edit]

The template is not working properly in the category Category:Orange textures (color), as the color orange does not show up in the list, possibly because of the part of the category name that says "(color)". Does anyone know why this causes it to malfunction in this category and what to do about it? —Kri (talk) 18:24, 28 July 2019 (UTC)[reply]

The template expects the (color) part to follow the colour's name directly. "Orange textures" is not a "color", so the category should be named Orange (color) textures, or Orange-colored textures. --Pitke (talk) 19:00, 2 June 2021 (UTC)[reply]

Excluding categories that don't belong?[edit]

@Benzoyl, Verdy p, Arnaud Palastowicz, Michael Barera, and Pitke:

Useful template, and thank you to everyone who's contributed.

However, having figured out(?) how it works, if I'm correct, it appears there's currently no way to explicitly exclude a category that happens to fit the naming pattern, but which doesn't actually belong? (Nor to include one which does, but which doesn't fit the pattern).

Case in point; Category:Blue mobile phones (and all others which include the template) automatically show a link to Category:Orange mobile phones purely because it exists. However, that category is currently for phones associated with the "Orange" mobile phone network(s) rather than orange-coloured phones, so it shouldn't be there.

Renaming the category would, of course, solve the problem. And since I'm not sure how the name in this case fits within naming conventions, it's possible that it should be changed anyway(?)

But there must be others where this isn't the case and (on general principle) it's not reasonable to rename such categories just to work around the issue?

Once again, thanks for the input from everyone involved, and please don't take this as a major criticism(!) of an otherwise useful template.

Ubcule (talk) 21:18, 1 June 2021 (UTC)[reply]

Thank you for the important information.
In this case, If renaming (create) Category:Orange (telecommunications) > Category:Orange (telecommunications) mobile phones,
Category:Orange mobile phones become equivalent = Category:Blue mobile phones Category:Red mobile phones (and other colors).
But, This is just my personal opinion. Thanks. --Benzoyl (talk) 21:32, 1 June 2021 (UTC)[reply]
For "Temporarily", I created just now Category:Orange (color) mobile phones. But I think better Category:Orange mobile phones & Category:Orange (telecommunications) mobile phones.
As needed in the future, of course, Category:Orange (color) mobile phones can redirect to Category:Orange mobile phones. I'll leave it up to you. Thank you very much. --Benzoyl (talk) 21:59, 1 June 2021 (UTC)[reply]
There is Category:Silver-colored mobile phones. Category:Orange-colored mobile phones is also the one naming way. --Benzoyl (talk) 22:03, 1 June 2021 (UTC)[reply]
Just my two cents, but I'd recommend renaming the category for the phones specific to the telecommunications company Category:Orange S.A. mobile phones and then making the color category simply Category:Orange mobile phones, with a prominent {{Cat see also}} or {{Distinguish}} at the top directing anyone looking for Orange S.A. phones to the proper category. I think that more people will expect "Orange" to be a color than a telecommunications company, although even I, as an American, am aware of Orange S.A. and know they are a telecommunications company. Again, just my two cents. Hope this helps! Michael Barera (talk) 17:15, 3 June 2021 (UTC)[reply]
@Michael Barera and Benzoyl: There are two issues here:-
  • The technical issues related to the template which caused the problem
  • Whether the name of the category is appropriate
To be clear, I intended this primarily as a discussion of the first (i.e. minor technical issue with the template), which is why it was brought up at Template_talk:By_color.
The specific "Orange mobile phones" category/template issue was what brought it to my attention, but we should be discussing the cause, not the symptom.
If the current category name isn't in line with the guidelines, it should be changed for its own sake regardless. If it's otherwise fine, then we shouldn't be renaming it simply to work round a limitation of a convenience template- that's allowing the tail to wag the dog.
It sounds like no-one else here has a clearer idea than myself of whether the current category name is appropriate or not. We probably shouldn't be moving it around for the sake of it. It might be a good idea to raise that issue elsewhere.
Ubcule (talk) 17:48, 3 June 2021 (UTC)[reply]
Edit; I've asked at the help desk for further advice, and if I get anything useful I'll report back. All the best! Ubcule (talk) 19:14, 3 June 2021 (UTC)[reply]
More at Commons:Categories for discussion/2021/06/Category:Orange mobile phones. Ubcule (talk) 20:49, 3 June 2021 (UTC)[reply]

Only working right in meta categories for me[edit]

Recently, I have been trying to create and fill the subcategories of the adolescent girls by clothing category. This includes making "by color" categories. I have included this template at the top of every "by color" category and subcategory.

However, it is not working in the way that I would like. In the meta-categories (such as Category:Adolescent girls wearing shirts by color), it works fine. It shows only the subcategories that exist, and it provides direct links to them. In the subcategories (such as Category:Adolescent girls wearing red shirts), it has not been working properly. Instead of providing links to the various subcategories of Category:Adolescent girls wearing shirts by color, it provides links to the subcategories of Category:Shirts by color.

Other categories (such as Category:Girls wearing red shirts) do not seem to have this issue at all, and I can't find any difference between what I'm doing and what seems to have been done in those categories. Evil Sith Lord (talk) 23:40, 28 June 2022 (UTC)[reply]

Hmm… Now it seems to work if I blank the page and manually add everything back. Evil Sith Lord (talk) 23:47, 28 June 2022 (UTC)[reply]
Well, that seemed to work for Category:Adolescent girls wearing blue shirts and the new Category:Adolescent girls wearing white shirts, but it isn't working anywhere else. Evil Sith Lord (talk) 23:54, 28 June 2022 (UTC)[reply]
In Category:Adolescent girls wearing red shirts, I changed the third parameter from 3 to prefix, which is what the template's documentation specifies. This now seems to be doing what you intended. The blue shirts and white shirts categories were already using prefix. Waz8 (talk) 02:12, 29 June 2022 (UTC)[reply]

Iridescent[edit]

This template needs support for "iridescent". We have categories for Category:Iridescent automobiles, Category:Iridescent minerals, Category:Iridescent animals, Category:Iridescent fishes, Category:Iridescent Coleoptera, etc. These are often organized within the "by color" conventions, but they don't get linked from the template. Nosferattus (talk) 16:39, 11 November 2022 (UTC)[reply]

I went ahead and added support to the template. Hope that's OK! Nosferattus (talk) 20:21, 11 November 2022 (UTC)[reply]

Not working randomly? Or with countries of Asia?[edit]

I copied the template 1:1 from Category:Men wearing blue neckties in Ukraine to Category:Men wearing blue neckties in Japan and changed all instances of "Ukraine" in the template to "Japan". The template works properly in the Ukraine category but not in the Japan category and I can't figure out why that is. Any ideas? Nakonana (talk) 15:06, 9 May 2024 (UTC)[reply]

It's possible that only Japan is affected by this problem. Nakonana (talk) 21:50, 9 May 2024 (UTC)[reply]