We Should Have Gutenberg Template Conditions

This should still be fixed, easiest by a condition that allows to apply a template to all pages using Gutenberg. These pages need a section with the page width to live in, so it looks like other pages.

On the other hand, for Bricks pages you mostly will add the whole section and its content, so no template is necessary. That’s one annoying thing, that makes my and certainly many new comers life harder. Especially as it seems the biggest builder Elementor allows this and many people finally switch from it to Bricks.

It’s often the small things, that can have a big impact.

Adding a CPT just to distinguish Bricks vs. Gutenberg build pages is a workaround, but not a professional one and something that adds any value, besides fixing a Bricks inconvenience.

You want pages to stay pages.

1 Like

I have to say that since moving from Oxygen to Bricks this is the greatest inconvenience I’ve found. In Oxygen I can drop into a page or a template, an area of content which is taken from Gutenberg. In this way a client can write or update their content in Gutenberg without messing up a page or template design. So simple and effective. Why this is not possible in Bricks is just beyond me.

3 Likes

I believe that a custom taxonomy for a page is a common practice. When developing a website, it is not difficult to add this.

What is written above is that it is in Elementor and it is because of this functionality that I have to spend a lot of time copying the content, since the user thought that it was possible to create pages both in Gutenberg and in the Elementor

At leat this workaround from Brickslabs does the job

@Matej
Can this still be addressed? It’s not beginner-friendly nor intuitive to overwrite all pages with a page template, even Bricks only pages. There should be a template condition for page with Wordpress content or Bricks pages should not be overriden.

The bricks/active_templates can be used to create additional conditions. The first example on the link below is to disable templates if Bricks data is detected on a page.

This video helped me achieve what I came here for. Thanks for spearheading a solution, and also for posting this video!

This would be handy, as sometimes you want to show gutenberg content and not build a page with Bricks. I came to Bricks from Oxygen Classic, which had a best practice template setup where if you added gutenberg content, it rendered it how you wanted in the template system, but as soon as you built something on the page with Oxygen, it would switch to showing Oxygen builder content only and the gutenberg stuff would not be rendered. I believe it used a built-in template hierarchy to do it.

I’m a bit weary of creating a work-around to achieve this in Bricks, because if I implement it on a bunch of sites and they all have to be updated in the future, it creates issues. Where a built-in feature for this would be much better.

It took me some time to get my head around this.

Having two separate content sources, Bricks and WP.

Bu now that I understand the concept, it’s kindof pretty cool. You can simply put create a post template and either put a Content Element in with WP as source or with Bricks as source. Or you can do BOTH. In which case either one will be rendered, whichever one has data. It becomes messy when BOTH have data.

For that, I have created a display condition which will allow you to select which one will be rendered. This allows you to filter for Bricks content. You do not need a filter for WP content because surely, you will want to display the WP stuff if there is no Bricks content.

On a side note, the dual content is cool because it allows you to create a Bricks content post and IN THAT POST add the content element with WP source, meaning you can insert the WP post data into the Bricks post. Meaning you could create a skeleton Bricks post which only Admins can change and your editors and contributors can change the WP content within it.

Anyhow, here’s a condition snipped that you’d have to add to your functions.php file or use any code snippet plugin. You could even add this as - probably (I have not tested this) - into your header as a Bricks code element.

/**

Snippet Name: Check for Bricksbuilder.op post data

@author    Ingo Ratsdorf

@link      https://ingo.envirology.co.nz

@version   1.0.0

Description: Adds a condition condition in Bricks Builder based on whether

there is Bricksbuilder content available or not.


Tested with 2.2RC.




Usage:

Add this snippet to your theme’s functions.php file or a custom code snippet plugin.
*/

class Has_bricksbuilder_content_condition {

public function __construct() {
    add_action('init', array($this, 'init'));
}

public function init() {
    // Add the new visibility condition to Bricks Builder
    add_filter('bricks/conditions/options', array($this, 'add_bricksbuilder_content_condition'));

    // Check the condition result
    add_filter('bricks/conditions/result', array($this, 'check_bricksbuilder_content_condition'), 10, 3);
}

public function add_bricksbuilder_content_condition($options) {
    $options[] = [
        'key'     => 'has_bricksbuilder_content',
        'label'   => esc_html__('Has Bricks Content', 'bricks'),
        'group'   => 'post',
        'compare' => [
            'type'    => 'select',
            'options' => [
                'Yes'  => esc_html__('Yes', 'bricks'),
                'No'  => esc_html__('No', 'bricks'),
            ],
        ]
    ];

    return $options;
}

public function check_bricksbuilder_content_condition($result, $condition_key, $condition) {
    // Only handle the custom 'has_bricksbuilder_content' condition
    if ($condition_key !== 'has_bricksbuilder_content') {
        return $result;
    }

    // Determine if the current device is mobile or desktop
    $current_device = wp_is_mobile() ? 'mobile' : 'desktop';

    // Get the selected condition values from Bricks or use default 'Yes'
    $compare = isset($condition['compare']) ? $condition['compare'] : 'Yes';

    // Try and get Bricksbuilder data for post
    $bricks_data = \Bricks\Database::get_data( get_the_ID(), 'content' );
    
    if ($compare === 'Yes') {
        return $bricks_data ? true : false;
    } elseif ($compare === 'No') {
        return $bricks_data ? false : true;
    }

    return $result;
}

}

new Has_bricksbuilder_content_condition();
1 Like