fbpx
Awesome

Split an ACF Flexible content field into Template Parts

If you’re like most WordPress Developers I know that use Advanced Custom Fields’ Flexible Content Field as a custom page builder, it’s likely you’ll be working with a large number of layouts.

All of the logic could be contained in one file however I prefer to split each ‘row’ into its own partial for easy maintenance.

For example, if I had row called testimonials_row I’d have a folder in my theme called components which would contain the partial testimonials_row.php.

Here’s a very simple example of how you could implement this in your projects:

<?php
// In a post/page template, loop over the ACF flexible field layouts and load the partial
// responsible for rendering the layout.
while ( the_flexible_field('my_flexi_field') ) {
get_template_part( 'components/'. get_row_layout() );
}

This is a Hookturn plugin ad block

This is a Hookturn plugin ad block

Built by Hookturn

This site was created by Hookturn, the team behind ACF Theme Code Pro. If you are interested in contributing or have an extension to add, email us.

Sponsored by Pressidium

Awesome ACF is sponsored by the very awesome team at Pressidium. If you need reliable, secure and scalable Managed WordPress Hosting, check them out.

Stay up to date with all things ACF

TODO: Registration form here