Toolset Conditional block allows you to display or hide blocks based on conditions you set. The conditional block can include multiple conditions and they can be nested.
The source of the tested data can be a standard or custom field, a Views shortcode that generates output or other custom shortcodes, or a PHP function that returns a value. The value can be compared against a fixed value (e.g. a number or a string), the value of another custom field, the result of a calculation using fixed values or custom fields, or Views date filters.
Inserting a Conditional block
Let’s start with an example. We have a site about cooking recipes. Each recipe displays information about preparation time, level of difficulty, and more.
We want to show a message to our visitors only if a certain dish can be prepared in under 30 minutes. To do that we add a Conditional block to our page. Next, we add a new block within that Conditional block. In this case, this will be a paragraph block but Conditional block can host any other block, including other conditional blocks. In the Block Editor, the Conditional block is located in the Toolset group of blocks. You can use multiple Conditional blocks on the same page or a template.
Setting the conditions
After adding the Conditional block, click the Add new conditions button.
Use the dialog that appears to select what to compare, the comparison operator, and the value to compare against.
In this dialog, you can also set the condition to be negative, add more conditions, link conditions by AND or OR operators, and group conditions.
Adding content to display conditionally
Next, we need to add content to display when the set conditions are met. To do that, position yourself within the Conditional block and add a new block with your content.
Checking the results
In our example, this is what our visitor will see.
If preparing time is less than 30 minutes
If preparing time is not less than 30 minutes
Advanced Editor mode
Use the Advanced editor switch to set conditions manually using the Views conditional rules. Please note that some conditions might be lost if you switch back to the Visual Editor mode.
- Creating and Displaying Repeatable Field Groups
- Displaying a Map on A Single Post Template
- Displaying a List of Posts on A Map
- Creating a Custom Search
- Creating a Hero Section
- Creating Sliders with Dynamic Post Content
- Adding Dynamic Content to Your Homepage
- Creating a View
- Creating a Custom Archive Page
- Creating Templates to Display Custom Posts
- Creating Responsive Columns and Grids
- Creating Responsive Designs
- Advanced Styling with Container Blocks
- Using Third-Party Hidden Fields