Change an attribute in render callback before the block is rendered server side

admin2025-01-07  7

I built a custom block that works similar to the paragraph block. However if a ToggleControl is switched it instead updates the excerpt. Whilst this correctly renders the current excerpt in both the edit and the save function, if the excerpt is changed outside of Gutenberg, such as via Wordpress admin, this block will not dynamically update.

I am looking for a way to use render callback to update the attribute before the block content is rendered.

<?php

// block render callback

if($attributes['use_excerpt']){
   $attributes['content'] = get_the_excerpt();
}

echo $content;

But content was not updated and clearly needs to parse again based on this change. I could preg_match between the tags but seems very clumsy. How is this supposed to be done?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736262294a807.html

最新回复(0)