How to display an ACF field with Timber using the post context
-
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?
Viewing 1 replies (of 1 total)
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.