Score:0

Node coloring by taxonomy

cn flag

My site has a node and a "tags" taxonomy that contain the color field. One node can have multiple tags, but I need to select one main tag. The color from the main tag must be passed to the node. How do I implement it?

leymannx avatar
ne flag
There are thousand ways to implement this. Most basic probably is that the tags have a color field with a select list to select predefined colors and each value represents a CSS class. In the node load the term, load it's color value and put that as a class like `<article class="color-{{ my_color }}>`.
pofk999 avatar
cn flag
One node can have 3-4 terms, but I need to somehow choose the main one from which the color will be taken. My problem is that there can be multiple terms. I was thinking about making two taxonomy references, but that's not a good idea because the main term will be duplicated in both fields
Kevin avatar
in flag
Make a single value taxonomy reference field to it, then you'll know what color to use. It's not duplication, it's just a second reference.
ru flag
You could - by convention - declare the first value as the main value. In the field settings, in the "help text" field, document that convention for your editors.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.