Support

Account

Home Forums Add-ons Flexible Content Field get_row_layout() not showing all layouts

Solved

get_row_layout() not showing all layouts

  • I inherited a site using ACF after my predecessor left my company, and I have never worked with WordPress or ACF before now.

    The theme of the site I’m managing has a custom page template called single-everfi-toolkit.php, which is pulling in layouts from a field called “Content Blocks”, which is Flexible Content:

    
    if (have_rows('content_blocks')) {
                                    while (have_rows('content_blocks')) {
                                        the_row();
    
                                        $everfi_fc_layout = get_row_layout();
                                        set_query_var('everfi_fc_layout',$everfi_fc_layout);
                                        set_query_var('everfi_fc_initial_cols', 4);//NOTE: refers to the bootstrap col-#
    
                                        get_template_part('includes/fc', $everfi_fc_layout); ?>
                                        <hr/>
                                    <?php }
                                }

    In the Includes folder of the theme are PHP files for all the existing layouts, with the prefixes “fc-” and then the name of the layout. I Add a Test Text layout to the Field in ACF, then made the corresponding PHP file “fc-test-text.php”:

    <?php
    $title = get_sub_field('block_title');
    $css_id = get_sub_field('css_id');
    $css_class = get_sub_field('css_class');
    ?>
    <section<?php echo($css_id ? ' id="' . $css_id .'"' : ''); ?> class="fc-test-text content-block<?php echo($css_class ? ' ' . $css_class : ''); ?>">
        <?php
        if($title){
            echo '<h3>'.$title.'</h3>';
        }
        ?>
        <?php
        if(get_sub_field('is_intro')){
            the_sub_field('intro_content');
        }
        ?>
        <div class="testTextContainer">
            <p><?php echo esc_html( get_field('text') ); ?></p>
        </div>
    </section>
    

    I can add my Test Text layout in my Content Blocks field when editing a toolkit page, and fill out all the fields as expected. However, the content does not show on the toolkit after saving. I tested existing layouts and they show just fine. Can anyone please help me understand what I need to do to get my Test Text content to show on the page as well?

  • When you created your new layout did ACF convert the layout name to “text_text”.

    I as because the only thing I can see here might be the name of the file you are trying to get.

    
    $everfi_fc_layout = get_row_layout();
    

    will assign the layout name saved in ACF. The file name must math this exactly using the code you have. “fc-test_text” will not load “fc-test-text.php”

    If this is the case you either need to change the layout name in ACF or change the file name.

  • Thanks John, I did ensure that my PHP file name was fc-text_text.php to match the name test_text. However the Test Text block is still not showing on the toolkit page after clearing my cache.

  • If the file name matches the layout name with “fc-” prepended and it is in the theme “includes/” folder then there isn’t any reason that is should not be working. You need to start looking into what is happening

    
    $everfi_fc_layout = get_row_layout();
    echo $everfi_fc_layout;
    
  • Welp, turned out I needed to clear my cache in WordPress after renaming my file. Can’t believe I forgot to do that. My new layout is now working as expected. Thanks so much for your help!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.