Custom location for the placeholder

Created on 11 August 2023, over 1 year ago
Updated 23 August 2023, about 1 year ago

Basically what I'm looking to do is load a block that renders header and footer content and then displays the Ajax results between the two.

When I add the ajax_placeholder it's always attached to the end of the render array so the block is rendered and displayed, but the 'loading' message is displayed underneath the already rendered content.

    $build['awesome'] = [
      '#type' => 'ajax_placeholder',
      '#callback' => ['my_custom_service:customLazyBuilder', []],
    ];
    $content = '<div id="custom-block" class="block-items">';
    $content .= '<div class="custom-links">';
    $content .= '<p><a href="https://google.com">Go to Google</a></p>';
    $content .= '<p><a href="https://microsoft.com">Go to Microsoft</a></p>';
    $content .= '</div>';
    $content .= '</div>';

What I'd like to do is something similar to how BigPipe works:

    $placeholder = 'my_custom_placeholder'. crc32('lazy custom block');
    $build['#attached']['placeholders'][$placeholder] = [
      '#type' => 'ajax_placeholder',
      '#callback' => ['my_custom_service:customLazyBuilder', []],
    ];

    $content = '<div id="custom-block" class="block-items">';
    $content .= $placeholder;
    $content .= '<div class="custom-links">';
    $content .= '<p><a href="https://google.com">Go to Google</a></p>';
    $content .= '<p><a href="https://microsoft.com">Go to Microsoft</a></p>';
    $content .= '</div>';
    $content .= '</div>';

Essentially I want the static block to load and display the loading message and Ajax data in a custom location. Is it possible to do this now?

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States RustedBucket

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024