Site logo

Archived topic

Query loop template

11 replies · Started by Taylor on February 19, 2023

Viewing posts 1–12 of 12

I'm trying to use Gutenberg block templates - https://www.billerickson.net/gutenberg-block-templates/ to automatically insert a query loop block with a pre-defined layout.

However everytime the page loads the query loop, it presents the templates selector with examples and "start blank". This causes it to not load my template inside the block.

How can I stop the template selector placeholder from loading and overriding the query loop template I set?

Hi,

I don’t think Local pattern will work.

I am creating my own custom block and using the innerBlock component and setting the query loop as the template to load when you add it.

Similar to how the query loop automatically inserts a grid and container block inside when you add it to the page.

Hi there,

i am not sure on this, but is it possible to see your templates code ?

So my template code looks like this:

$template = [
    [ 'generateblocks/query-loop',
        [ 
            [
                'query' => ['post_type' => 'post'],
                'lock' => ['remove' => true]
            ],
            ['generateblocks/grid',
                [
                    'isDynamic' => true,
                    'blockVersion' => 3,
                    'isQueryLoop' => true,
                    'lock' => ['remove' => true],
                ],
                ['generateblocks/container',
                    [
                        'isGrid' => true,
                        'isQueryLoopItem' => true,
                        'blockVersion' => 3,
                        'lock' => ['remove' => true, 'move' => true],
                    ],
                    [ 'core/heading', 
                        [ 'content' => 'This is a title' ]
                    ]
                ]
            ]
        ]
    ]
];

<div class="myCustomBlock">
    <InnerBlocks
        template="<?= esc_attr( wp_json_encode( $template ) ); ?>"
    />
</div>

I am not sure its possible to overcome that, as the template is literally inserting the block onto the page, so it will initiate the layout selector.

I assume nothing changes if you add more params to the 'query' => ['post_type' => 'post'], arg ?

No, adding params doesn’t change anything.

As a suggestion for a solution, could you perhaps add a key like

Layout-selector => false

Or even a hook to completely disable the layout selector popup globally as I start blank In most cases anyway.

I have asked Tom and Jean to take a look, in case there is something that could be leveraged today, if not we'll take a look at adding one.

Thank you for looking into it ♥️

That should technically work as our layout selector only displays if there are no inner blocks present.

Can you share your entire code (how you register the template as well) so I can try it on my dev server?

Thanks!

Strange, it's possible that using that method doesn't allow our block to recognize any innerBlocks. We'll look at a filter to skip the layout selector.

Glad you found an alternative solution!

This archived topic is closed to new replies.