• Resolved christdg

    (@christdg)


    So for the before_template and after_template actions

    the before_template and after_template hooks both call 3 variables – $field,$layout,$is_preview

    but somewhere after the before_template action is called and before the after_template action is called, the values of $field and $layout gets modified so its not the same structure.

    Im not sure if it something that I did wrong…

    I had to add $og_field and $og_layout and set them at the top of the function and then use them in the after_template filter callouts

    /*
     * ACFE: Flexible Render Layout Template
     * Find & include the Flexible Content Layouts PHP files
     */
    function acfe_flexible_render_layout_template($layout, $field){
        
        //GET ORIGIONAL VALUES OF THE FIELD AND LAYOUT VARIABLES
        $og_field = $field;
        $og_layout = $layout;
    
        // Global
        global $is_preview, $col;
        $col = false;
        
        // Vars
        $name = $field['_name'];
        $key = $field['key'];
        $l_name = $layout['name'];
        
        // File
        $file = acf_maybe_get($layout, 'acfe_flexible_render_template');
        
        // Filters
        $file = apply_filters("acfe/flexible/render/template",                                      $file, $field, $layout, $is_preview);
        $file = apply_filters("acfe/flexible/render/template/name={$name}",                         $file, $field, $layout, $is_preview);
        $file = apply_filters("acfe/flexible/render/template/key={$key}",                           $file, $field, $layout, $is_preview);
        $file = apply_filters("acfe/flexible/render/template/layout={$l_name}",                     $file, $field, $layout, $is_preview);
        $file = apply_filters("acfe/flexible/render/template/name={$name}&layout={$l_name}",        $file, $field, $layout, $is_preview);
        $file = apply_filters("acfe/flexible/render/template/key={$key}&layout={$l_name}",          $file, $field, $layout, $is_preview);
        
        // Deprecated
        $file = apply_filters_deprecated("acfe/flexible/layout/render/template/layout={$l_name}",              array($file, $field, $layout, $is_preview), '0.8.6.7', "acfe/flexible/render/template/layout={$l_name}");
        $file = apply_filters_deprecated("acfe/flexible/layout/render/template/name={$name}&layout={$l_name}", array($file, $field, $layout, $is_preview), '0.8.6.7', "acfe/flexible/render/template/name={$name}&layout={$l_name}");
        $file = apply_filters_deprecated("acfe/flexible/layout/render/template/key={$key}&layout={$l_name}",   array($file, $field, $layout, $is_preview), '0.8.6.7', "acfe/flexible/render/template/key={$key}&layout={$l_name}");
        
        // Before Template
        do_action("acfe/flexible/render/before_template",                                       $field, $layout, $is_preview);
        do_action("acfe/flexible/render/before_template/name={$name}",                          $field, $layout, $is_preview);
        do_action("acfe/flexible/render/before_template/key={$key}",                            $field, $layout, $is_preview);
        do_action("acfe/flexible/render/before_template/layout={$l_name}",                      $field, $layout, $is_preview);
        do_action("acfe/flexible/render/before_template/name={$name}&layout={$l_name}",         $field, $layout, $is_preview);
        do_action("acfe/flexible/render/before_template/key={$key}&layout={$l_name}",           $field, $layout, $is_preview);
        
        // Deprecated
        do_action_deprecated("acfe/flexible/layout/render/before_template/layout={$l_name}",               array($field, $layout, $is_preview), '0.8.6.7', "acfe/flexible/render/before_template/layout={$l_name}");
        do_action_deprecated("acfe/flexible/layout/render/before_template/name={$name}&layout={$l_name}",  array($field, $layout, $is_preview), '0.8.6.7', "acfe/flexible/render/before_template/name={$name}&layout={$l_name}");
        do_action_deprecated("acfe/flexible/layout/render/before_template/key={$key}&layout={$l_name}",    array($field, $layout, $is_preview), '0.8.6.7', "acfe/flexible/render/before_template/key={$key}&layout={$l_name}");
        
        // Check file
        if(!empty($file)){
        
            $file_found = acfe_locate_file_path($file);
            
            if(!empty($file_found)){
                
                // Front-end
                if(!$is_preview){
                    
                    // Include
                    include($file_found);
                    
                // Preview
                }else{
        
                    $path = pathinfo($file);
                    $extension = $path['extension'];
        
                    $file_preview = substr($file,0, -strlen($extension)-1);
                    $file_preview .= '-preview.' . $extension;
        
                    $file_preview = acfe_locate_file_path($file_preview);
        
                    // Include
                    if(!empty($file_preview)){
        
                        include($file_preview);
                        
                    }else{
        
                        include($file_found);
                        
                    }
                    
                }
                
            }
            
        }
        
        // After Template
        //USE OG VALUES OF LAYOUT AND FIELD VARIABLES
        do_action("acfe/flexible/render/after_template",                                        $og_field, $og_layout, $is_preview);
        do_action("acfe/flexible/render/after_template/name={$name}",                           $field, $layout, $is_preview);
        do_action("acfe/flexible/render/after_template/key={$key}",                             $field, $layout, $is_preview);
        do_action("acfe/flexible/render/after_template/layout={$l_name}",                       $field, $layout, $is_preview);
        do_action("acfe/flexible/render/after_template/name={$name}&layout={$l_name}",          $field, $layout, $is_preview);
        do_action("acfe/flexible/render/after_template/key={$key}&layout={$l_name}",            $field, $layout, $is_preview);
        
        // Deprecated
        do_action_deprecated("acfe/flexible/layout/render/after_template/layout={$l_name}",                array($field, $layout, $is_preview), '0.8.6.7', "acfe/flexible/render/after_template/layout={$l_name}");
        do_action_deprecated("acfe/flexible/layout/render/after_template/name={$name}&layout={$l_name}",   array($field, $layout, $is_preview), '0.8.6.7', "acfe/flexible/render/after_template/name={$name}&layout={$l_name}");
        do_action_deprecated("acfe/flexible/layout/render/after_template/key={$key}&layout={$l_name}",     array($field, $layout, $is_preview), '0.8.6.7', "acfe/flexible/render/after_template/key={$key}&layout={$l_name}");
        
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback! It’s weird, I just tested it and I got the same output for both $field & $layout in the before/after hooks. I used a version diff software to check differences, and there is none.

    Here is my test code:

    add_action('acfe/flexible/render/before_template', 'my_before_template', 10, 3);
    function my_before_template($field, $layout, $is_preview){
        
        echo "<pre>".print_r($field, true)."</pre>";
        echo "<pre>".print_r($layout, true)."</pre>";
    
    }
    
    add_action('acfe/flexible/render/after_template', 'my_after_template', 10, 3);
    function my_after_template($field, $layout, $is_preview){
        
        echo "<pre>".print_r($field, true)."</pre>";
        echo "<pre>".print_r($layout, true)."</pre>";
    
    }
    

    Note that I just added one layout in the Flexible Content. It is normal that the $layout is different if you use different layouts, since it will represent the current layout used in the row.

    What difference do you see on your side?

    Regards.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Any news?

    Regards.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘After Template – action hook’ is closed to new replies.