Support

Account

Home Forums Add-ons Flexible Content Field Reuse layout multiple times on page Reply To: Reuse layout multiple times on page

  • This is not an error in the flex field, but in your logic. You are only setting a new value for the 3 variables if the field has a value, but you not resetting or unsetting the previous value it in the next iteration of the loop.

    
    <?php
    if( have_rows('content') ):
    while ( have_rows('content') ) : the_row();
    	
    	if ( get_row_layout() == 'textblock' ):
    
    		$title = '';
    		if( get_sub_field('title') ):
    			$title =  get_sub_field( 'title' );
    		endif;
    		$lead = '';
    		if( get_sub_field('lead') ):
    			$lead = get_sub_field( 'lead' );
    		endif;
    		$body = '';
    		if( get_sub_field('body') ):
    			$body = get_sub_field( 'body' );
    		endif;
    		?>
    	
    		<section class="textblock">
    			<?php echo $title ?>
    			<?php echo $lead ?>
    			<?php echo $body ?>
    	        </section>
        
    	<?php
    	else :
    	endif;
    	?>	    
    		              	              
    <?php
    endif;
    endwhile;
    endif;
    ?>