email m.palmowski@freshpixels.pl
wordpress.org profiles.wordpress.org/palmiak
github github.com/palmiak
Timber Collaborator github.com/timber/timber
I work at WPMU DEV
email m.palmowski@freshpixels.pl
wordpress.org profiles.wordpress.org/palmiak
github github.com/palmiak
Timber Collaborator github.com/timber/timber
I work at WPMU DEV
Let's use create-guten-block because, based on author info:
Installation
npx create-guten-block my-block
cd my-block
npm start
├── .gitignore
├── plugin.php
├── package.json
├── README.md
├── dist
| ├── blocks.build.js
| ├── blocks.editor.build.css
| └── blocks.style.build.css
└── src
├── block
| ├── block.js
| ├── editor.scss
| └── style.scss
├── blocks.js
├── common.scss
└── init.php
Only two steps to go:
add_action('acf/init', 'my_acf_init');
function my_acf_init() {
if( function_exists('acf_register_block_type') ) {
acf_register_block_type([
'name' => 'trips',
'title' => __('Trips'),
'description' => __('Promoted trips'),
'render_callback' => 'my_acf_block_render_callback',
'category' => 'layout',
'icon' => 'location-alt',
'keywords' => [ 'trips', 'flights' ],
]);
}
}
You can see all the options here: https://www.advancedcustomfields.com/resources/acf_register_block/
<?php function my_acf_block_render_callback( $block, $content = '', $is_preview = false ) {
// do stuff here
}
<?php the_field( 'name' ); ?>
<?php the_field( 'description' ); ?>
FROM <?php the_field( 'price' ); ?> EUR
But some stuff is missing:
function my_acf_block_editor_style() {
wp_enqueue_style(
'trips_css',
get_template_directory_uri() .'/dist/css/editor.css'
);
wp_enqueue_script(
'trips_js',
get_template_directory_uri() .'/dist/js/editor.js'
);
}
add_action( 'enqueue_block_editor_assets', 'my_acf_block_editor_style' );
acf_register_block_type([
'name' => 'trips',
'title' => __('Trips'),
'description' => __('Promoted trips'),
'render_callback' => 'my_acf_block_render_callback',
'category' => 'layout',
'icon' => 'location-alt',
'keywords' => [ 'trips', 'flights' ],
'enqueue_style' => get_template_directory_uri() .'/dist/css/editor.css',
'enqueue_script' => get_template_directory_uri() .'/dist/js/editor.js',
]);
.gutenberg-sasquatch-block {
@import "components/colors";
@import "components/mixins";
@import "components/standards";
@import "components/typo";
@import "components/buttons";
@import "layouts/index";
}
It doesn't work because:
window.acf.addAction('render_block_preview', function( $el, attributes ){
$.bridget( 'packery', Packery, $ );
if ( $( '.offers-list').length ) {
imagesLoaded( $( '.offers-list' ), function() {
$( '.offers-list' ).each( function( i ) {
$( '.offers-list' ).packery(
{
itemSelector: '.item',
}
);
});
});
}
});
{#
Title: Testimonial
Description: Customer testimonial
Category: formatting
Icon: admin-comments
Keywords: testimonial quote "customer testimonial"
Mode: edit
#}
{{ fields.testimonial }}
{{ fields.author }}
You can read more about Timber ACF WP Blocks on https://github.com/palmiak/timber-acf-wp-blocks
If you don't use Timber try https://github.com/MWDelaney/sage-acf-wp-blocks or https://github.com/micropackage/block-loader