Site logo

[Support request] Query loop template

Home Forums Support [Support request] Query loop template

Home Forums Support Query loop template

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #2538674
    Taylor

    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?

    #2539183
    Fernando
    Customer Support

    Hi Taylor,

    Our solution for this would be to use GB Pro’s Local Pattern feature. Reference: https://docs.generateblocks.com/article/pattern-library-overview/

    #2539261
    Taylor

    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.

    #2539651
    David
    Staff
    Customer Support

    Hi there,

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

    #2540321
    Taylor

    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>
    #2541025
    David
    Staff
    Customer Support

    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 ?

    #2541042
    Taylor

    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.

    #2541101
    David
    Staff
    Customer Support

    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.

    #2541116
    Taylor

    Thank you for looking into it ♥️

    #2543422
    Tom
    Lead Developer
    Lead Developer

    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!

    #2546285
    Taylor

    I’m using BlockStudio which supports InnerBlocks.

    BlockStudio passes the template prop directly to the react InnerBlock component same as you would if you built the block using react.

    My template markup is here – https://generatepress.com/forums/topic/query-loop-template/#post-2540321

    Howevever, I found an alternative solution which didn’t require the use of the query loop innerBlock template

    #2548035
    Tom
    Lead Developer
    Lead Developer

    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!

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.