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 the Advanced Custom Fields – Flexible Content Field as a custom page builder, it’s likely you’ll be working with a large Flexible Content Field.

All of the logic could be contained in one file however I prefer to split each ‘row’ into it’s own partial so for easily management & 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 testimoinals_row.php.

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

<?php 
// loop over the ACF flexible fields for this page / post 
while ( the_flexible_field('my_flexi_field') ) {
      
      // load the component from the components folder  
	  get_template_part( 'components/'. get_row_layout() );

} ?>					

Keep up to date with all things ACF!

Subscribe to our newsletter or follow @awesomeacf on Twitter!