[Support request] Displaying complex variables in an Element.

Home Forums Support [Support request] Displaying complex variables in an Element.

Home Forums Support Displaying complex variables in an Element.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1504045
    Andrew

    I’m using Meta Box to create custom fields for use in Elements – and they work great together – but a lot of the variables are more complex that a simple variable. In my case I’m wanting to retrieve a variable within an array – something like {{custom_field.array_name.variable_name}}

    Also – As the field is conditional – I’d like to display the CTA conditionally. eg.

    {% if custom_field.group_cta_fields %}
        {{custom_field.group_cta_fields.text_cta}}
    {% endif %}

    Is this possible?

    or is it possible to somehow add a hook area conditionally within an Element?

    Thanks.

    #1504055
    Elvin
    Staff
    Customer Support

    Hi Andrew,

    I’m afraid you can’t do conditional statements w/ template tags.

    However, you should be able to do that with shortcodes.

    You can make a shortcode that does that.

    Here’s how to make a shortcode: https://docs.generatepress.com/article/creating-a-shortcode/

    #1504106
    Andrew

    Thanks. What about targeting variables in arrays?

    #1504107
    Elvin
    Staff
    Customer Support

    foreach PHP iteration of variables should work within the shortcode.

    You can even add conditions within it too.

    Example:

    ...
    foreach($array as $items ) { 
        $custom_field = $items->custom_field_name; 
        if(!$custom_field){
            //do something if $custom_field is empty.
        } else if ($custom_field){
            //do something if $custom_field has a value.
        }
    }
    ...
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.