Set Gutenberg block variable from template
-
We have a small plugin that adds
template
s to thepage
post-type
and everytemplate
needs to have aGutenberg block
calledhero
. Thehero
block has anattribute
calledhero-type
, which can be “Story”, “Primary”, “Secondary” and “Tertiary”.Some
template
s however require a specifichero-type
. For example, thenews-overview
needs to have the “Secondary”. How do we go on about doing this?We have done this for our
post-types
, where we have added for example the “Story”hero-type
to the “Story”post-type
.Here is the code how we created the templates:
<?php function website_theme_templates($post_templates, $obj, $post, $post_type) { $CUSTOM_TEMPLATES = [ 'page' => [ 'home' => 'Home page', 'contact' => 'Contact', 'news-overview' => 'Overview: News', 'story-overview' => 'Overview: Story' ] ]; return array_merge($post_templates, isset($CUSTOM_TEMPLATES[$post_type]) ? $CUSTOM_TEMPLATES[$post_type] : []); } add_filter( 'theme_templates', 'website_theme_templates', 4, 10 );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Set Gutenberg block variable from template’ is closed to new replies.