Home › Forums › Gutenberg › Is there any way to style the container for InnerBlocks? › Reply To: Is there any way to style the container for InnerBlocks?
ok, I found a really janky way to do this, but it works. Open to ideas for improvements:
In JS you can use the blocks.registerBlockType filter to add a getEditWrapperProps function to all blocks (or just the ones you need). Ex:
wp.hooks.addFilter(
'blocks.registerBlockType',
'plugin/add-acf-ids',
function ( settings, name ) {
return lodash.assign( {}, settings, {
getEditWrapperProps: (props) => {
return {'data-acfid': props.id}
},
});
}
);
Then in my renderBlock function I have something like this:
$previewStyles = "";
if($isPreview) {
$previewStyles = "<style>#editor .wp-block[data-acfid='{$acf['id']}'] {{$styles}}</style>";
$styles = "";
}
$preBlock = $this->filter("Block/$slug/start", "<{$tag} class='aesir-builder__block {$slug} {$classes}' style='{$styles}'>\n{$previewStyles}", $block, $classes, $styles, $previewStyles, $slug, $tag, $content, $isPreview, $postID);
That’s boilerplate wrapped around all my blocks, so I provide $styles from a class that defines my block, and it gets translated into either inline styles for frontend, or a style tag for the editor.
I hate everything about this, but at least it’s kinda working.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.