• Resolved diondetovenaar

    (@diondetovenaar)


    Hi there,

    What is best practice to load the corresponding template for each flexible layout?

    I don’t wan’t to place the path to the template in the plugin settings. I would like to place those via the theme or plugin.

    In your documentation is explained that you can use the filter ‘filter(‘acfe/flexible/render/template’. But if you have like 20 or more layouts, you would need to create 20 separate functions where each function is pointing to the location of one template. That sounds a bit overkill.

    Is there a way to load every corresponding layout template from within one file?

    For example i use the filter ‘acfe/flexible/enqueue/name=sections’ to enqueue one stylesheet for all layouts in admin.

Viewing 1 replies (of 1 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback, and sorry for the late answer, I’m kinda busy with the upcoming patch lately.

    As you pointed out, you have to use the acfe/flexible/render/template in order to define your own custom layouts files path.

    As described in the documentation, this hook has a lot of variations, including wildcard variations which will be applied to layouts within a specific flexible content field. So you don’t have to create 20 different functions.

    Here is a usage example:

    // note that 'name=my_flexible_content'
    // this hook will be executed on all layouts of the Flexible Content named 'my_flexible_content'
    add_filter('acfe/flexible/render/template/name=my_flexible_content', 'my_flexible_content_render_file', 10, 4);
    function my_flexible_content_render_file($file, $field, $layout, $is_preview){
        
        // check the layout name
        if($layout['name'] === 'my_layout'){
            $file = 'my-layout.php';
            
        // check another layout name
        }elseif($layout['name'] === 'my_other_layout'){
            $file = 'my-other-layout.php';
        }
        
        // return
        return $file;
        
    }

    Hope it helps!

    Have a nice day!

    Regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Dynamic render templates’ is closed to new replies.