• Resolved alvarofranz

    (@alvarofranz)


    I want to display an ACF field in the front end. It’s a text value within a group.

    • Group name: banner
    • Field name: text

    See screenshot:

    I added the value in two different ways to the context:

    // Add whole post to context
    $context = Timber::get_context();
    $post = new Post();
    $context['post'] = $post;
    
    // Add specific value to context
    $post_data = get_field_objects();
    if (isset($post_data['banner']['value'])) {
        $banner = $post_data['banner']['value'];
        $context['banner_text'] = $banner['text'];
    }

    Then, in twig, I do:

    TEXT from post context: {{ post.banner.text }}<br>
    TEXT from forced value: {{ banner_text }}

    And I get this result:

    TEXT from post context:
    TEXT from forced value: “the value i wrote for this field”

    The provided value via context is not set.

    What am I doing wrong? Isn’t this how I am supposed to display ACF fileds with Timber?

    • This topic was modified 1 year, 3 months ago by alvarofranz.
Viewing 1 replies (of 1 total)
  • Thread Starter alvarofranz

    (@alvarofranz)

    Looks like the correct way to get the field when it’s in a group is:

    {{ post.meta('groupname').fieldname }}

    So, instead of:

    {{ post.banner.text }}

    It’s:

    {{ post.meta('banner').text }}
    • This reply was modified 1 year, 3 months ago by alvarofranz.
Viewing 1 replies (of 1 total)
  • The topic ‘How to display an ACF field with Timber using the post context’ is closed to new replies.