Home › Forums › Gutenberg › ACF Field Data in Block (HTML) Template › Reply To: ACF Field Data in Block (HTML) Template
Hi Tony,
Thanks for the responses! The shortcode idea is a good one and works nicely, and I’ll use it in the future when I need to quickly access ACF data from an HTML template.
I ended up just making new ACF blocks for the content that I wanted to display, and then inserting those blocks into the HTML templates. If you or anyone else stumbling on this doesn’t know, ACF has a handy register block function that can be used to quickly register a block without going through the endorsed WordPress route (which uses JSX and has separate Save and Edit functions for rendering).
I registered a person block, for instance, and then could add it to my HTML template with the following code:
<!-- wp:acf/person {"id":"block_627aa5c420a3d","name":"acf/person"} /-->
Then I can supply that block a good old fashioned PHP template during registration, allowing me to fully access the ACF field data from the render template and to further dictate how that block is displayed in the HTML template.
Like you said, this solution doesn’t seem elegant, nor is it efficient if you need to do it for many different types of posts.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.