[Support request] Conditional Blocks in Block Element

Home Forums Support [Support request] Conditional Blocks in Block Element

Home Forums Support Conditional Blocks in Block Element

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1828122
    Liam

    Hi there,

    I’m currently converting one of my sites to Block Elements. I’ve created a Content Template Block Element for my archives, and my question is the following: Is it possible to have conditional (Generate)Blocks in that template? The site is a food blog, and I’d like to display icons/text for vegetarian, low-card, etc. I know I can create templates for individual categories, but to get all combinations covered. The diet terms are a custom taxonomy (a vegetarian meal gets assigned the “vegetarian” category in the taxonomy “diet” etc.).

    Thanks for any help!
    Liam

    #1828348
    David
    Staff
    Customer Support

    Hi there,

    you can use the Dynamic Text type – List Terms and select your custom taxonomy. If there are no Terms for a specific post that field will not be displayed.

    #1831705
    Liam

    Hi David

    Thanks for the reply. I think I should have given a bit more information. My question is whether there is something like an “if/then” function for individual blocks. E.g. if the recipe is vegetarian, then the button block with a plant icon will be displayed and if not, then not.

    #1831721
    Elvin
    Staff
    Customer Support

    Hi Liam,

    It’s going to be real tricky to do but it may be doable with generate_dynamic_element_text filter:

    Not sure if this is 100% accurate but you can play around with this example:

    add_filter( 'generate_dynamic_element_text', function( $custom_field, $block ){
        if ( 'term-meta' === $block['attrs']['gpDynamicTextCustomField'] ) {
            if(your condition here){
    	        $custom_field = '';
            }
        }
        return $post_date;
    },15,2);
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.