• Resolved David Ramírez

    (@davidhobo)


    Hi i would like to use just one styleshhets in the preview mode for all my layout. because i use prepocessor SCSS.

    I use the filter with param “name=” to point all the layout inside my Flexible content field. like this:

    add_filter('acfe/flexible/render/style/name=my_name', 'acf_flexible_layout_render_style', 10, 4);
    function acf_flexible_layout_render_style($style, $field, $layout, $is_preview){
    
        // Only in Ajax preview
        if($is_preview){
    
            return get_stylesheet_directory_uri() . '/assets/css/acf-layout-styles-preview.css';
    
        }
    
        return get_stylesheet_directory_uri() . '/assets/css/acf-layout-styles.css';
    
    }

    The problem is enqueue the same stylesheet repeatedly. as many as number of layouts on the same page ( Backend & Frontend )

    Thanks in advance, awesome plugin!

    • This topic was modified 3 years, 6 months ago by .
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback. The acfe/flexible/render/style filter is used to override layouts style files from what is saved within the UI. Your targeting name=my_name, actually force all layouts of the flexible content to enqueue a custom file. This is why it is repeatedly enqueued (enqueued handle names are generated based on the layout name).

    In order to enqueue one new style/script file for the whole flexible content, you should use the acfe/flexible/enqueue action. Usage example:

    add_action('acfe/flexible/enqueue/name=my_name', 'my_acf_flexible_enqueue', 10, 2);
    function my_acf_flexible_enqueue($field, $is_preview){
    
        // Only in Ajax preview
        if($is_preview){
    
            wp_enqueue_style('my-style-preview', 'https://www.example.com/style-preview.css');
    
        }
    
        wp_enqueue_style('my-style', 'https://www.example.com/style.css');
    
    }
    

    You’ll find more examples in the related FAQ question.

    Hope it helps!

    Regards.

    Thread Starter David Ramírez

    (@davidhobo)

    Oh yeah!

    Thanks a lot for the fast reply.

    It’s work perfect! Now i can mantain my SCSS structure and compile 1 stylesheet for backend preview and 1 stylesheet for frontend.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    I’m glad to hear it now works as you wanted!

    If you enjoy the plugin, feel free to submit a review. It always helps and it’s much appreciated 🙂

    Have a nice day!

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Flexible content render – compile styles’ is closed to new replies.