Support

Account

Home Forums Gutenberg ACF Block / modify template output in Gutenberg

Unread

ACF Block / modify template output in Gutenberg

  • Hello,

    Im trying to set a Gutenberg flag in ACF Block template by trying to check if template is actually loaded in Gutenberg or in frontend.

    <?php
    
    /**
     * Testimonial Block Template.
     *
     * @param   array $block The block settings and attributes.
     * @param   string $content The block inner HTML (empty).
     * @param   bool $is_preview True during AJAX preview.
     * @param   (int|string) $post_id The post ID this block is saved to.
     */
    
    // Create id attribute allowing for custom "anchor" value.
    $id = 'testimonial-' . $block['id'];
    if( !empty($block['anchor']) ) {
        $id = $block['anchor'];
    }
    
    // Create class attribute allowing for custom "className" and "align" values.
    $className = 'testimonial';
    if( !empty($block['className']) ) {
        $className .= ' ' . $block['className'];
    }
    if( !empty($block['align']) ) {
        $className .= ' align' . $block['align'];
    }
    
    // Load values and assign defaults.
    $text = get_field('testimonial') ?: 'Your testimonial here...';
    $author = get_field('author') ?: 'Author name';
    $role = get_field('role') ?: 'Author role';
    $image = get_field('image') ?: 295;
    $background_color = get_field('background_color');
    $text_color = get_field('text_color');
    
    global $current_screen;
    $current_screen = get_current_screen();
    if ( method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor() ) {
        $flag = 'Gutenberg';
    }
    
    ?>
    <section id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($className); ?> container">
      <div class="row">
        <div class="col-4">
          <span class="testimonial-text"> <?php echo $flag.$text; ?></span>
        </div>
        <div class="col-4">
            <span class="testimonial-author"><?php echo $author; ?></span>
        </div>
        <div class="col-4">
          4
        <div class="testimonial-image">
            <?php echo $image['url']; ?>
        </div>
      </div>
        </div>
      </div>
    </section>
    

    The flag is empty …
    Any idea why?

    Best
    P.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.