Support

Account

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.