fbpx
If you're working on a project with lots of Flexible content field 'rows' it can really help to break them 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() );
}

Keep up to date with all things ACF!

Subscribe to our newsletter or follow @awesomeacf on Twitter!