function template_preprocess_gutenberg_block in Gutenberg 8.2
Prepares variables for Gutenberg block templates.
Default template: gutenberg-block.html.twig.
Parameters
array $variables: An associative array containing:
- block_name: The block name.
- block_attributes: Array of block attributes.
- block_content: The block's inner content.
File
- ./
gutenberg.theme.inc, line 35 - Theme related functions and hooks for the Gutenberg module.
Code
function template_preprocess_gutenberg_block(array &$variables) {
// Add the default Gutenberg wp-block- class.
$block_name = str_replace('/', '-', $variables['block_name']);
if (substr($block_name, 0, 5) === 'core-') {
// Handle "core/*" blocks specially.
$block_name = substr($block_name, 5);
}
$variables['attributes']['class'][] = 'wp-block-' . $block_name;
}