Create/Modify a default page template without having to exclude all the other pages

Is there a way to assign a default page template to all pages, but without overwriting pages build with bricks, and without having to exclude every single pages we do not want to use this template.
Exemple, if we want pages made by a client in Gutenberg to use the default template, but we want something different than the default one by bricks builder.
In the child-theme, we modified the page.php template with the template shortcode and it’s working, but there should be an easier solution.
Maybe just a ‘Default page’ in the template types dropdown?

The only way I know how to do this is to apply a taxonomy to pages using something like ACF and using an acf field to pick the taxonomy for each post/page and then setting up an exclusion for the specific option e.g. (Without template) so then you can just choose option to not render the template. You could also have options for no header and footer or combinations.

1 Like

Hey @JohnF,

if I understand your scenario correctly you can use the bricks/active_templates hook. In your case it should look something like this:

add_filter( 'bricks/active_templates', function( $active_templates, $post_id, $content_type ) {
    if ( ! bricks_is_frontend() ) {
        return $active_templates;
    }

    if ( $content_type !== 'content' ) {
        return $active_templates;
    }

    $post_type = get_post_type( $post_id );

    if ( $post_type !== 'page' ) {
        return $active_templates;
    }

    $bricks_data = \Bricks\Database::get_data( $post_id, 'content' );

    if ( empty( $bricks_data ) ) {
        return $active_templates;
    }

    $active_templates['content'] = $post_id;

    return $active_templates;
}, 10, 3 );

This makes sure that pages do not use the configured page template if they are built with Bricks themselves.

Let me know if it helps.

Best,

André

I wrote about this in a blog post a while back. I used a template that applies to every page, and created a function that tests if the page has Bricks content on it.

Yes! this is exacly what i was looking for.
Thank you André!