Hi @palmiak,
It’s not really documented in ACF but I found this thread where Steffi explain how to declare block styles with acf_register_block_type() : https://support.advancedcustomfields.com/forums/topic/adding-block-styles-to-an-acf-custom-block/
I took a closer look at your plugin and manage to integrate styles.
Styles could be declared on a single line and separated with an underscore like this :
{#
Title: Bouton
Description: Theme button
Styles: btn--primary,Primary _btn--primary--sm,Primary S _btn--basic,Basic _btn--basic--sm,Basic S
#}
Each style is then exploded to be declared as a php array in your plugin :
// Support styles
if ( ! empty( $file_headers['styles'] ) ) {
$data['styles'] = array();
// Styles exploding with underscore '_'
$style = explode('_', $file_headers['styles']);
foreach ($style as &$value) {
// Styles data exploding with comma ','
// [1]=slug [2]=label
$style_data = explode(',', $value);
array_push($data['styles'], array('name' => $style_data[0],'label' => $style_data[1]));
}
}
I didn’t manage to make “isDefault’ style works but there seems to be a bug here with acf_register_block_type().
Best,
Hi @palmiak
Did you get any chance to have a look at this block style issue ?
thanks !
Hi @palmiak,
I managed to use your script with a custom integration into my theme, it works perfectly, thanks a lot.
I tried to register block styles for a custom button with no success.
Can you show an example of the syntax ?
{#
Title: Bouton
Description: Theme button.
Category: common
Styles : ???
#}
Thanks,
I confirm that this method works fine !
I mixed it with another method (https://elod.in/adding-wordpress-color-palettes-into-the-acf-color-picker/) and automated the whole process to generate the color for Gutenberg and Acf. It works like a charm.
Hi,
I’m a big fan of Timber and ACF block and I really love the idea to register a block just by adding a template to a theme’s folder.
Does your plugin support Block styles variations ?
+1 this feature would be really great, thanks !
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.