Support

Account

Home Forums Add-ons Flexible Content Field Clone partial used in multiple contexts

Solved

Clone partial used in multiple contexts

  • I have a clone field that is used in 2 places:

    – Homepage
    – Flexible Content field

    I have a template partial that displays the fields from the clone.

    I include the partial in the Homepage template and I include the partial in the flexible content field.

    The partial uses get_field to display each field.

    When included in the homepage, the fields are displayed.

    When included in the flexible content field, the fields are not displayed, because it needs to use get_sub_field.

    Is there a way to have 1 clone field partial that can be used for a page, and also within a flexible content field?

    Thanks

    Homepage

    get_template_part( 'components/clones/split-col');

    Flexible content

    if( have_rows('page_builder_content_blocks') ):
    
      while ( have_rows('page_builder_content_blocks') ) : the_row();
    
        if( get_row_layout() == 'page_builder_split_column' ):
    
          get_template_part( 'components/clones/split-col');      
    
        endif;
    
      endwhile;
    
    endif;

    Partial

     <div>
        <?php if (get_field('split_col_title')) : ?>
          <h2><?php the_field('split_col_title'); ?</h2>
        <?php endif; ?>
    
        <?php if (get_field('split_col_text')) : ?>
          <?php the_field('split_col_text'); ?>
        <?php endif; ?>
      </div> 
  • In your home page or anywhere that the clone field in not in a repeater (flex field) you can clone the field into a group field.

    Add a have_rows() loop on the group field and include the same template part

  • Yes that works, thank you

    if( have_rows('home_page_intro') ):
      while ( have_rows('home_page_intro') ) : the_row();
        get_template_part( 'components/clones/split-col');
      endwhile;
    endif;
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.