Support

Account

Home Forums Add-ons Flexible Content Field Conditionally Show Flexible Content Layout

Solved

Conditionally Show Flexible Content Layout

  • Hi,

    I’m building a framework that I want to reuse across multiple sites, so I’m building a flexible content field with various layouts. E.g.

    Layout: Document Library (and subfields)
    Layout: Slideshow (and subfields)
    Layout: Accordion (and subfields)

    Now if a build a theme that I only want to support the slideshow layout, is there the ability to only render out the Slideshow layout, and hide all the others in the backend?

    The ability to add conditional logic would be perfect… but any solution would be appreciated.

    Thank you

  • Hi @michael-ord

    Hmm… ACF may not have a ready solution for this but I believe it is achievable.

    One way to achieve this would be to hide the layout name from the popup which appears when you click the ‘add row’ button. Each link had a data-layout attribute i.e. <a ... <em><strong>data-layout='layout_name'</strong></em> ...>layout label</a>. This attribute can be used to hide the layout name from the popup.

  • Hi @acf-support / James,

    Not an ideal solution, but I got it sorted thanks to your suggestion, and hopefully, if AFC builds in support for this, it will be super easy to switch out.

    Thank you! 🙂

  • If you’re doing a parent theme -> child theme framework.

    You can make your fields and create separate directories for each of the json files in the parent theme.

    
    acf/library/fields.json
    acf/slideshow/fields.json
    acf/accordion/fields.json
    

    In the child themes functions.php you can set custom load directories.

    
    function acf_json_load_paths( $paths ) {
    
      // Loads alls json files from the /acf-json folder in the child theme
      $paths = array(get_template_directory() . '/acf-json');
    
      // If this theme is a child theme it will load all the fields in the acf-json/library directory
     
      if(is_child_theme()) {
        $paths[] = get_stylesheet_directory() . '/acf-json/library';
      }
    
      return $paths;
    
    }
    add_filter('acf/settings/load_json', 'mw_acf_json_load_paths');
    

    Not sure if this the right solution.

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

The topic ‘Conditionally Show Flexible Content Layout’ is closed to new replies.