{"id":1292451,"date":"2019-09-09T22:29:37","date_gmt":"2019-09-09T22:29:37","guid":{"rendered":"https:\/\/toolset.com\/?post_type=course-lesson&#038;p=1292451"},"modified":"2020-11-18T14:17:32","modified_gmt":"2020-11-18T14:17:32","slug":"using-toolset-conditional-block","status":"publish","type":"course-lesson","link":"https:\/\/toolset.com\/fr\/course-lesson\/using-toolset-conditional-block\/","title":{"rendered":"Display Content Conditionally"},"content":{"rendered":"\n<p>You can test data from a standard or&nbsp;<a href=\"https:\/\/toolset.com\/fr\/glossary\/custom-fields\/\">custom field<\/a>, a Views output or other custom shortcodes and functions. The value can be compared against a fixed value like a number, the value of another custom field, dates, and more.<\/p>\n\n\n\n<p>For example, you can create conditions that check for empty values of custom fields, check for the current user&#8217;s role, or check for values in taxonomy terms.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Inserting a Conditional block<\/h2>\n\n\n\n<p>Let\u2019s start with an example. We have a site about cooking recipes. Each recipe displays information about preparation time, level of difficulty, and more.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"4091bc6b2d4250e97d959b1fcfeb828a\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/07\/toolset-conditional-page-1.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/07\/toolset-conditional-page-1-500x530.png\" alt=\"\" class=\"wp-image-1305609\"\/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>We want to show a message to our visitors only if a certain dish can be prepared in under 30 minutes.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>We add a Toolset&nbsp;<strong>Conditional&nbsp;<\/strong>block to our page. Of course, you can use multiple&nbsp;<strong>Conditional&nbsp;<\/strong>blocks on the same page or a template.<\/li><li>Next, we add a new block within that&nbsp;<strong>Conditional&nbsp;<\/strong>block. In this case, this will be a paragraph block but&nbsp;<strong>Conditional&nbsp;<\/strong>block can host any other block, including other conditional blocks. <\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"cd37f4819518b9ae409dcfbfe7b1e9b2\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/09\/toolset-conditional-block-add-conditional-block.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/09\/toolset-conditional-block-add-conditional-block-402x486.png\" alt=\"Adding Conditional block\" class=\"wp-image-1333509\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Adding Conditional block<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Setting the conditions<\/h2>\n\n\n\n<p>After adding the&nbsp;<strong>Conditional<\/strong>&nbsp;block, click the&nbsp;<strong>Add new conditions<\/strong>&nbsp;button.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"752324ccbdf468a07291ae3dc22dd008\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/09\/toolset-conditional-block-add-conditions.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/09\/toolset-conditional-block-add-conditions-500x240.png\" alt=\"Add new conditions\" class=\"wp-image-1333527\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Add new conditions<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Use the dialog that appears to select what to compare, the comparison operator, and the value to compare against.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"bfff780475531f3d18de659e5943a27b\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/09\/toolset-conditional-block-edit-conditions.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/09\/toolset-conditional-block-edit-conditions-500x197.png\" alt=\"Editing your condition rules\" class=\"wp-image-1333561\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Editing your condition rules<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Adding content to display conditionally<\/h2>\n\n\n\n<p>Next, we need to add content to display when the set conditions are met. To do that, position yourself within the <strong>Conditional <\/strong>block and add a new block with your content.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Checking the results<\/h2>\n\n\n\n<p>In our example, this is what our visitor will see.<\/p>\n\n\n\n<div class=\"wp-block-toolset-blocks-grid tb-grid\" data-toolset-blocks-grid=\"9cbc03461b87a40447ddc413b8a01dd9\">\n<div class=\"wp-block-toolset-blocks-grid-column tb-grid-column tb-grid-align-top\" data-toolset-blocks-grid-column=\"3034fbe886c11054e95b46b09d3e4112\">\n<p><strong>If preparing time is less than 30 minutes<\/strong><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-toolset-blocks-grid-column tb-grid-column tb-grid-align-top\" data-toolset-blocks-grid-column=\"3034fbe886c11054e95b46b09d3e4112\">\n<p><strong>If preparing time is not less than 30 minutes<\/strong><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-toolset-blocks-grid-column tb-grid-column tb-grid-align-top\" data-toolset-blocks-grid-column=\"c3eb1d1ec6485ba563815b1cab509a25\"><div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"cb1e8a545834c908f030ce225a29068c\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/07\/toolset-conditional-page-show.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/07\/toolset-conditional-page-show-500x504.png\" alt=\"\" class=\"wp-image-1305429\"\/><\/a><\/figure>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-toolset-blocks-grid-column tb-grid-column tb-grid-align-top\" data-toolset-blocks-grid-column=\"697a8b470baf2bd0aba1fe56f0c92c0d\"><div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"4a08106b2e175c21950d39b416f8e17f\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/07\/toolset-conditional-page-hidden.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2019\/07\/toolset-conditional-page-hidden-500x459.png\" alt=\"\" class=\"wp-image-1305439\"\/><\/a><\/figure>\n<\/div><\/div>\n<\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n","protected":false},"author":4341,"featured_media":1779759,"template":"","related-lesson":[8421,8409,8417,8427,8411],"class_list":["post-1292451","course-lesson","type-course-lesson","status-publish","has-post-thumbnail","hentry","related-lesson-custom-search","related-lesson-archive-pages","related-lesson-designing","related-lesson-post-templates","related-lesson-view"],"_links":{"self":[{"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/course-lesson\/1292451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/course-lesson"}],"about":[{"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/types\/course-lesson"}],"author":[{"embeddable":true,"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/users\/4341"}],"version-history":[{"count":8,"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/course-lesson\/1292451\/revisions"}],"predecessor-version":[{"id":1779741,"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/course-lesson\/1292451\/revisions\/1779741"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/media\/1779759"}],"wp:attachment":[{"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/media?parent=1292451"}],"wp:term":[{"taxonomy":"related-lesson","embeddable":true,"href":"https:\/\/toolset.com\/fr\/wp-json\/wp\/v2\/related-lesson?post=1292451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}