Using dynamic content (nested) for a color field

I have a looper which lists a series of events by date. I also have categories for the events.
I am using dc to look up the category of each item in the looper and display the category name. This works fine. But I have also used ACF to create a custom color for each category. When I try to use this value to set the background color of the div, it fails.
If I take my same dc code and display it, I can see the rgba value just fine though.
My code for displaying the category name:
{{dc:term:name term="{{dc:acf:post_field field=\"kategori\"}}"}}
My code for the color associated with the category:
{{dc:acf:term_field field="hendelse_farge" term="{{dc:acf:post_field field=\"kategori\"}}"}}

So, the second code displays fine when I use it as text, displaying the rgba() value correctly, but doesn’t work in the color field itself.

I also used this code for the color but got the same results:
{{dc:term:meta term="{{dc:acf:post_field field=\"kategori\"}}" key="hendelse_farge"}}

Any ideas?

Hi Steve,

Thanks for reaching out.
Without investigation, it won’t be easy to recognize what exactly is happening. I would suggest you please provide login credentials for your site in a secure note to examine it further, including:

– WordPress Site URL & Login URL
– WordPress Admin username/password
– Exact page or layout where you have used it.

To create a secure note, click the key icon underneath any of your posts.

Thanks

Updated secure note now.
See how I am able to display the result of:
{{dc:term:meta term="{{dc:acf:post_field field=\"kategori\"}}" key="hendelse_farge"}}
as a text field, but it doesn’t work as the background color:
Screenshot 2024-06-25 at 13.44.32

Hi Steve,

I have checked with the Meta Field value through the Dynamic Content and set that in the background color, and it worked perfectly. While using the Category id {{dc:term:meta term=“26” key=“hendelse_farge”}} instead of {{dc:acf:post_field field=“kategori”}} this works fine to. It seems the nested Dynamic Content is not working here, I will check with our development team on this and let you know.

Thanks

Thanks for your support. I was thinking of testing it with the RC1 but didn’t do that yet.

Unfortunately looper data is not used in style generation it seems. It’s partially a good thing as it means looper items don’t output CSS for every single item and it uses one class per each item. As a result though we’ll need to figure out a way to determine changes in these instances. I’ve written a bug report on this, but it sounds a little complicated from my seat.

As a workaround the only way I could get this to work is using custom attributes. You could also add global CSS and give each specific term type a class. Let me know if this helps.

1 Like

Thanks @tristup and @charlie - using the custom attribute method seems to work fine and is pretty easy to implement. Thank you both for your help, I was really stuck with this one and you came through as always :grinning:

1 Like

Hi Steve,

Glad that we are able to help you.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.