AdvancedCustomFields / AdvancedCustomFields/acf
Gutenberg Block Feedback & Timber / Twig Implementation
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
Hi Elliot,
i want to give you some Feedback for the new Gutenberg Blocks:
First of all I have to say that you did a very great job there, i had nearly the same idea a few month ago to build a plugin for easy Gutenberg Block creation with Twig Support... now you came up with this and its exactly what i thought about and needed 👍 I played around the last days and was able to easily convert my existing Twig Slider including Repeater Fields in a fully functional Gutenberg Block without changing any Part of the existing Code (nearly) . I want to Share my way with you guys maybe its helpfull and something for the docs.
Detected Bugs:
- Fields that are wrapped in Tabs wont get Saved (First Tab is working)
Feature request // Help request :
- I need to get a unique id for the Gutenberg Block - ive seen you have a unique id in the json string but I wasnt able to get it yet
- Maybe a function that wraps all found fields in a post array with their fieldname so you get the old structure back
Twig/Timber Implementation
Here you can find my actual Twig Implementation, Twig Templates are located in Views/Gutenberg and are working the same way like before by accessing variables through {{post.field_name}}. The only Placeholders you need to change in your existing templates are the ones with {{ post.get_field('field_name')}} they will be avaible with {{post.field_name}} now. If you have any Improvements or Questions i would be happy to get some Feedback for the Twig Implementation:
<?php
function acf_gutenberg_init() {
if( function_exists('acf_register_block') ) {
// Testblock
acf_register_block(array(
'name' => 'testblock',
'title' => __('Testblock'),
'description' => __('A custom testimonial block.'),
'render_callback' => 'my_acf_block_render_callback',
'category' => 'formatting',
'icon' => 'admin-comments',
'keywords' => array( 'testblock', 'quote' ),
));
// Slider
acf_register_block(array(
'name' => 'testslider',
'title' => __('Test Slider'),
'description' => __('TestSlider'),
'render_callback' => 'my_acf_block_render_callback',
'category' => 'formatting',
'icon' => 'admin-comments',
'keywords' => array( 'testblock', 'quote' ),
));
}
}
add_action('acf/init', 'acf_gutenberg_init');
function my_acf_block_render_callback( $block ) {
// convert name ("acf/testimonial") into path friendly slug ("testimonial")
$slug = str_replace('acf/', '', $block['name']);
// include a Twig template part from within the "views/gutenberg/" folder and set Post Array Fields
$context['post'] = array(
'titel' => get_field('titel'),
'slider' => get_field('slider'),
'bild_overlay' => get_field('bild_overlay'),
'height' => get_field('height'),
'minheight' => get_field('minheight'),
'id' => get_field('id'),
);
Timber::render("/gutenberg/{$slug}.html.twig", $context );
}
Greetings
Pierre
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The report does not name repository files or tests. Start by reviewing the Gutenberg block field-saving flow and the sample render callback, then reproduce the tabbed-field issue; done should include a defined fix for saving fields in all tabs and a separately agreed scope for the block ID and post-array requests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- content
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100