Block templates using Reusable blocks?
-
Hi,
I need some help. I’m just starting out customizing using gutenberg, so perhaps I just have missed something.
I’m trying to add a call to action to be shown show in all posts and have created a reusable block for that. It works fine, but has to manually be added, what can be forgotten.
I found out how block templates can be used to prefill new posts with blocks and that is very useful too.
So now I could add the call to action block as a normal block and try to prefill it, or I can find out if a template can be used to add a reusable block too.
Optimal for my user case would be to add a standard block, with fixed settings and content. Using a reusable block seems better equipped to discourage editing the block, but I haven’t found any example of how such a block can be added to a block template.
And trying to prefill the non-reusable version of the block, I also run into trouble, and don’t know how to prevent or discourage users from changing the settings or content in the editor. So my preference would be using a reusable block.
My questions:
– Can anyone tell me if and how a reusable block can be used in a block template?The call 2 action is added by the genesis block plugin and is basically a div that contains a h2 title, followed by a text area ( a div on the frontend) that can contain one or more paragraphs and a button. I was able to prefill all settings and content, except for the ctaText that has paragraphs as children.
When I examine the block in console using:
wp.data.select( 'core/block-editor' ).getSelectedBlock().attributes;
It shows me that ctaText is an array that contains an
object { type: 'p', props: {...}}
. The props open up as an object which contain children which contain the text.Anyone know a way to reach such a child to prefill it?
If none of this works, I will probably just need to filter the_content and add some html programmatically, but I rather learn how to use gutenberg for such things.
The template documentation is a start, but not yet an answer for all questions. The obvious question is how to find out in a given case how to address the settings of a block and what the arrays mean in case of the nested blocks. I see empty arrays being passed there, but don’t know why they are there and what other use they have. I’ld like to be able to find that kind of info.
Any help is greatly appreciated.
Hans
- The topic ‘Block templates using Reusable blocks?’ is closed to new replies.