• Resolved rose18

    (@rose18)


    Hi there,

    I have used the ‘Flexible Content’ field type to create different layouts, and one of it is a ‘photo slider’ layout.
    Within the ‘Photo slider’ flexible layout, it has a ‘Relationship’ field to select one ‘slider’ from the Custom Post Type ‘Photo Slider'(screenshot: https://snipboard.io/Bs2duk.jpg).
    In the admin preview, I don’t want to display the actual slider, but replace it with the following text message:
    “[Photo Slider]Cannot display preview in the admin.”

    The slider will only be displayed in the front-end.

    I did try to use these hooks: ‘Before Layout Render’ and ‘After Layout Render’, and did it in a similar way to replace gravity form shortcodes with a custom text message.
    However, it doesn’t work the way I wanted.

    
    acfe/flexible/render/after_template/layout=my_layout
    acfe/flexible/render/before_template/layout=my_layout
    

    my code:

    
    add_action('acfe/flexible/render/before_template/layout=gallery_slider_block', 'flexible_disable_slider_preview', 10, 3);
    function flexible_disable_slider_preview($field, $layout, $is_preview){
        if($is_preview){
          echo '<div style="padding:50px 0; text-align:center; background:#f4f4f4;">[Photo Slider]<br> Cannot display preview in the admin.
    </div>';
        }
    }
    

    It does display the message in the admin, but the slider is still there in the admin preview. (screenshot: https://snipboard.io/ms5fIV.jpg)
    I would like to replace the slider (which is using the ‘Relationship’ field type) with some text rather than displaying the slider in the admin preview.

    How can I accomplish this?

    Thanks!

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

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    The acfe/flexible/render/before_template & acfe/flexible/render/after_template actions let you add an element or perform a specific action before/after your template inclusion.

    If you want to display a specific message in the admin or in the front-end, you can simply use the $is_preview as a condition, directly within your layout-template.php. See documentation.

    Usage example – Template /layouts/hero/template.php:

    <?php
    
    /*
     * Hero Layout Template
     *
     * @array   $layout      Layout settings (without values)
     * @array   $field       Flexible content field settings
     * @bool    $is_preview  True in Administration
     */
     
    ?>
    <div class="layout-hero">
    
        <h1>Hero</h1>
        
        <?php if($is_preview){ ?>
            
            Admin preview message.
            
        <?php }else{ ?>
            
            <?php the_sub_field('my_field'); ?>
            
        <?php } ?>
        
    </div>
    

    Hope it helps!

    Have a nice day!

    Regards.

    Thread Starter rose18

    (@rose18)

    Thank you @hwk-fr !

    It works perfectly!

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    You’re welcome!

    If you enjoy this plugin and its support, 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 ‘Dynamic Preview – Replace slider with a custom text message in admin preview’ is closed to new replies.