Unfortunately this doesn't work, the color of the icon doesn't change to green e.g. when I inject msg.color = "green".
Instead this work, but I like to understand why:
The problem is, that copying such a template will mean much more adaption effort since I need to make the name unique in order to get it working in case I have more than one of such templates. Therefor the first solution can be used out of the box without manual adaption effort.
The first method doesn't work because Node-RED's template node doesn't directly support binding attributes like fill within the SVG element. It's not able to dynamically change the SVG attribute based on the value of msg.color . The second method using CSS works because it applies the style to the SVG using an ID selector, which is supported by Node-RED's template node.
Thanks for the quick reply. So I thought changing it to this will reduce the adaption effort as well, but setting the ID dynamically doesn't work either. Any idea how to get this working?
I pass in the node id which in fact is unique, this looks similar to 22a1e4a43f772235. When inspecting with developer tools inside my chrome browser, I see this Id got replaced, however it doesn't show up the desired color.
I already have a global css template defined, but I didnāt know how to define the mentioned class and access it within the svg id property.
Maybe a stupid question but I am not that fimilar to html/css.
@Steve-Mcl thanks for the links. I am struggling with the correct selector. I set my classname in a function like that:
if (msg.payload === false)
{
msg.classname = "white-svg";
msg.payload = "M 480 -180 q -66 0 -113 -47 t -47 -113 H 200 q -33 0 -56.5 -23.5 T 120 -420 q 0 -140 92 -241.5 T 440 -778 v -122 h 80 v 122 q 136 15 228 116.5 T 840 -420 q 0 33 -23.5 56.5 T 760 -340 H 640 q 0 66 -47 113 t -113 47 Z M 200 -420 h 560 q 0 -116 -82 -198 t -198 -82 q -116 0 -198 82 t -82 198 Z m 280 160 q 33 0 56.5 -23.5 T 560 -340 H 400 q 0 33 23.5 56.5 T 480 -260 Z m 0 -80 Z";
}
else
{
msg.classname = "yellow-svg";
msg.payload = "M 480 -180 q -66 0 -113 -47 t -47 -113 H 200 q -33 0 -56.5 -23.5 T 120 -420 q 0 -140 92 -241.5 T 440 -778 v -122 h 80 v 122 q 136 15 228 116.5 T 840 -420 q 0 33 -23.5 56.5 T 760 -340 H 640 q 0 66 -47 113 t -113 47 Z M 200 -420 h 560 q 0 -116 -82 -198 t -198 -82 q -116 0 -198 82 t -82 198 Z m 280 160 q 33 0 56.5 -23.5 T 560 -340 H 400 q 0 33 23.5 56.5 T 480 -260 Z m 0 -80 Z M 440 -20 v -120 h 80 v 120 h -80 Z m -246 -126 L 138 -204 L 224 -288 L 280 -232 L 194 -146 Z M 766 -143 l -84 -86 l 56 -56 l 86 86 l -58 56 Z";
}
Nope, it return not available. And if a select the svg tag and click copy selector I do not get something realy useful #Erdgeschoss_Zimmer_Benno_cards > md-card:nth-child(12) > svg.
If that doesnt work, try setting the fill of the path to "currentFill" or "currentColor" or removing the fill attribute from the path altogether. As a last resort, add !important