Support

Account

Home Forums Gutenberg ACF + Timber

Solving

ACF + Timber

    • palmiak

    • April 21, 2020 at 5:30 pm

    If you’re using Timber and ACF Blocks I would like you to try https://github.com/palmiak/timber-acf-wp-blocks

    You can declare blocks using file comments eg.

    
    {#
      Title: Testimonial
      Description: Customer testimonial
      Category: formatting
      Icon: admin-comments
      Keywords: testimonial quote "customer testimonial"
      Mode: edit
      Align: left
      PostTypes: page post
      SupportsAlign: left right
      SupportsMode: false
      SupportsMultiple: false
    #}
    
    <blockquote data-{{ block.id }}>
        <p>{{ fields.testimonial }}</p>
        <cite>
          <span>{{ fields.author }}</span>
        </cite>
    </blockquote>
    
    <style type="text/css">
      [data-{{ block.id }}] {
        background: {{ fields.background_color }};
        color: {{ fields.text_color }};
      }
    </style>

    If you’ll find a bug or something don’t hesitate to post an issue.

    • vinsan

    • April 29, 2020 at 5:22 pm

    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 ?

    • palmiak

    • April 30, 2020 at 9:42 am

    Hi @vinsan

    Nice to hear you’re a fan of Timber and ACF 🙂

    I just read a bit about BSV and it’s looks like it’s more related to ACF itself than to my plugin. If something works in ACF than it should work in my plugin too. But I have good news – it works 😉 I just tested it. The only problem is a bit related to the way how the thumbnails are generated (depends on the preview mode), but overall it works like a charm.

    • vinsan

    • April 30, 2020 at 11:15 pm
    This reply has been marked as private.
    • vinsan

    • May 4, 2020 at 12:25 am
    This reply has been marked as private.
  • Hi – I’ll take a look on it during the upcoming days. On first sight it looks OK.

    Also I’m planing to have a plugin version too.

    • vinsan

    • May 4, 2020 at 8:06 am

    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,

    • vinsan

    • May 15, 2020 at 5:49 pm

    Hi @palmiak

    Did you get any chance to have a look at this block style issue ?

    thanks !

    • vinsan

    • May 24, 2020 at 9:25 pm

    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,

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.

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.