Site logo

[Support request] Content Template – Dynamic Container Background color or class

Home Forums Support [Support request] Content Template – Dynamic Container Background color or class

Home Forums Support Content Template – Dynamic Container Background color or class

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2451504
    Matt

    Hi Guys,

    Just wondering if there is any way to either dynamically set the background color of a container, or set a class on a container for a content template (or the content template wrapper).

    I have a content template setup for my archives and want to allow the user to select a background color for one of the inner containers. Ideally I would use an ACF select field to give the user some pre-set options for classes or colours.

    Thanks

    #2451715
    David
    Staff
    Customer Support

    Hi there,

    if the content wrapper is a GB Container Block in the element, then you can add CSS Class to Advanced > Additional CSS Class(es).

    Then you can add whatever style to that class.

    Does that work for you ?

    #2452144
    Matt

    Hi David,

    Not really. I need to do it per-post. So.. on render of the content template (for each post), get the value of the ACF field and either add a class to the article or inline style to the container.

    #2452256
    Fernando
    Customer Support

    Hi Matt,

    Yes, you can do that. Either add an inline style depending on the returned value of your ACF field.

    You can basically use the render_block filter to render the Block with your ACF “style”. Or you can append a class and utilize this class to associate a specific background color depending on the custom field.

    Reference: https://developer.wordpress.org/reference/functions/render_block/

    #2452262
    Matt

    Great.. Thanks for your assistance!

    #2452265
    Fernando
    Customer Support

    You’re welcome, Matt!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.