In a repeated element fetched from a REST API , I want to use the hexadecimal color code from the data fetched in the background color of the item.
Any idea ?
In a repeated element fetched from a REST API , I want to use the hexadecimal color code from the data fetched in the background color of the item.
Any idea ?
I tried with the embed HTML component, but can’t find a way to retrieve $props inside it :
<script>
let id = $props.orientationId;
let color = $props.orientation.color;
$('#cardOrientation-'+id+' .cardOrientation-heading').css('background-color', color);
$('#cardOrientation-'+id+' .cardOrientation-relatedMesures').css('color', color);
</script>
Hello @vincent_wasteels, welcome to the community.
There’s no way to set a dynamic value for a background color right now. Your workaround using Embed HTML should work. Can you share your project link?
Ok , do you know if it is in the roadmap ?
The link to the project :
https://studio.plasmic.app/projects/ajDfwtmjeNR7jYxfpFhaiK/-/card-orientation?arena_type=component&arena=ZvLSmpKsMLP3
it throws an js error once published, $props is not defined
Thank you!
You can add a style attribute and set a dynamic value on it that uses $props
. Here’s how:
Use the following code:
{
backgroundColor: $props.orientation.color
}
Here’s the output:
@sarah_ahmed thanks a lot, this is exactly what I was looking for