Site logo

Archived topic

Blocks and Patterns

9 replies · Started by Dan on January 24, 2021

Viewing posts 1–10 of 10

Hi, I've got a question regarding block patterns. Maybe not directly linked to Generate Press and GB, but since it's my go-to theme and blocks plugin I wanted to raise this topic:

I would like to use block patterns as we used to use page templates, meaning:
1. Create a block pattern
2. Insert the block into the page
3. Edit the content of the blocks in the pattern (text and media changes mainly)
4. Use across a few pages
Now, what happens if you want to add a block to the pattern? I would like it to update across all the pages that have the pattern inserted. Is that possible?
Setting up a css class for the pattern can help with global styling the blocks in the pattern via a css file, but I am wondering about actually adding or moving blocks in the pattern and have that reflect on all the instances of the patterns inserted in the site.

Example:
Think product pages for example, I have 50 products, each page created with the “Product pattern”, now I want to add a testimonials block to the pattern. Instead of going through 50 pages, I would just need to add it to the pattern and it will show up across all pages.

Makes sense?

Thanks in advance for your guidance,

Dan

Hi there,

Now, what happens if you want to add a block to the pattern? I would like it to update across all the pages that have the pattern inserted. Is that possible?

I could be wrong but I don't believe this is possible within the Gutenberg editor yet.

You could check with WordPress' support team and see if it's possible or it could be a feature suggestion.

Thanks Leo and Ying, would you think there is a way to create a 'Block pattern template' with a block element, where I could construct a series of blocks and then apply them to a specific page (via display rules). Then, if I change something inside the block element (one of the blocks, add or remove a block), that change would be applied to all the places where the block element is displayed?

Dan

Block element should work like that by default no?

I thought you were talking about something like reuseable blocks.

I would like to create a layout of blocks (like a pattern) but doesn't have to be a 'Gutenberg pattern' per say.
Then I would be able to insert that pattern-of-blocks into a page. If I would need to further edit these blocks in the block element I could do so and the edit would reflect on all applied elements - I think that up to here we are good with block elements.

Now, is there a way to call the block element into a page not with a hook but with a shortcode? or maybe with a php filter (I remember Tom menitoned a new filter he was introducing for creating page layouts), or even with an ACF select box where the user can select which layout he would like to display.

I don't know where Ying's comment disappeared, it's not here.

Dan

Now, is there a way to call the block element into a page not with a hook but with a shortcode

I don't believe there is a way to do that yet. Even with the local templates from GB pro, they don't update automatically when you update them in the template file:
https://docs.generateblocks.com/article/template-library-overview/#local-templates

I believe the filter you are talking about is the generate_do_template_part and that's for building post loop templates.

So currently it will be on a per specific page basis to apply the block element? or creating a Custom post type? because the current location rules do not have a page template option.

does this function tell element id to display in the hook location we set in the element on the 'templates/jjma.php' page template?

add_filter( 'generate_layout_element_display', function( $display, $element_id ) {
    if ( 123 === $element_id ) {
        if ( is_page_template( 'templates/jjma.php' ) ) {
            $display = true;
        }
    }

    return $display;
}, 10, 2 );
This archived topic is closed to new replies.