Rendering the icon in the configured color in Views - how to?

Created on 24 November 2024, about 1 month ago

Problem/Motivation

I want to render the icon in the configured color.

On the module page it says:

Rendering icons in Views

How the icon is rendered is completely up to you to determine. It's expected that you'll be using an icon font, but ultimately you could use the icon setting in any way you wish (i.e. to contextually render an SVG, add a class, etc.). For a simple use case using Material Icons, add the "Content type icon" field to the "Content" View and rewrite the output of the field to match

That works as expected. I added the icon. And it appears. Also the plain color code is displayed as extra field.

Rendering colors in Views

Views doesn't allow users to add style attributes to rewritten/custom text, which makes adding a color to a field pretty hard. To get around this limitation while maintaining Views security, Type Style will replace the data-type-style-color and data-type-style-background-color attributes in a Views row with the relevant style code, as long as you add the "Content type color" field to the output as a hidden field.

Where do I need to put these: Type Style will replace the data-type-style-color and data-type-style-background-color in order to change the color of the icon itself?

And I also cannot reproduce how the color is added to the views row.
I added the hidden color field. But the attributes of the row is not changed. Do I need to put a token value somewhere?

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Active

Version

1.2

Component

Documentation

Created by

🇦🇹Austria maxilein

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024