One of my entities has a attribute for a color. When displaying this entities in a template grid I want to use that attribute to color a part of the template card. So I would like to be able to do something like --> style= "color:$MyEntity/Color;" Is this somehow possible?
I did something like this before and had to resort to the usage of the HTML snippet. Here is an instruction of how it could be implemented.
Make sure the attribute which holds the color has hexadecimal formatted string values, like #FF0000 for pure red;
Give that attribute a specific class (attrClass) in the form;
Place all the parts of the page you want to style in a container element (in Modeler);
Give this container you want to style with the value of this attribute another class (targetContainerClass);
Retrieve the HTML element by targeting the attrClass with something like:
var attr = document.getElementsByClassName("attrClass");
Get the content of the element with the .textContent property and store in a variable;
var color = attr.textContent;
Get the HTML element of the targetContClass element in the same manner with something like:
var containerTarget = document.getElementsByClassName("targetContainerClass");
Set the background of this element with something like:
containerTarget.style.backgroundColor = color;
You can also use the (official Mendix) customString widget, which lets you run a microflow that returns a string, which you can display with HTML elements. In this you can 'construct' a element with a variable color.
'<div style="background-color: ' + $Object/colorAttribute + ';">I like cake</div>
You could create containers which have a color specific class added to them, and show the 'correct' containers through conditional visibility in Mendix as per your attribute.