{"id":852,"date":"2023-08-10T13:31:54","date_gmt":"2023-08-10T12:31:54","guid":{"rendered":"https:\/\/www.help.headlight.tech\/?post_type=ht_kb&#038;p=852"},"modified":"2023-08-10T13:31:55","modified_gmt":"2023-08-10T12:31:55","slug":"how-can-i-add-specific-conditions-inside-of-a-workflow-component-message","status":"publish","type":"ht_kb","link":"https:\/\/www.help.headlight.tech\/?ht_kb=how-can-i-add-specific-conditions-inside-of-a-workflow-component-message","title":{"rendered":"How can I add specific conditions inside of a workflow component message?"},"content":{"rendered":"\n<p>Headlight workflows support condition components, which allow you to branch your workflow off into different directions. However, this is not the only way to implement conditions into your workflows. For smaller scale conditions, such as message personalizations, you can use conditions directly in the body of text in your workflow. In order to achieve this, Headlight supports the Jinja2 standard for templating. You probably use some Jinja2 syntax in your workflows when displaying parameters using <a href=\"https:\/\/www.help.headlight.tech\/?ht_kb=what-are-workflow-parameters\" data-type=\"URL\" data-id=\"https:\/\/www.help.headlight.tech\/?ht_kb=what-are-workflow-parameters\">their references<\/a>. You can also create conditions based on parameters.<\/p>\n\n\n\n<p>Concretely, you can add conditions using the following structure<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>{% if exampleTest %} Text if <em>exampleTest<\/em> is true <br>{% elif exampleTest2 %} Text if <em>exampleTest2<\/em> is true <br>{% else %} Fallback result if none of the other conditions were true <br>{% endif %}<\/p>\n<\/blockquote>\n\n\n\n<p>An example use case for this is <a href=\"https:\/\/www.help.headlight.tech\/?ht_kb=how-can-i-create-multilingual-workflows\" data-type=\"ht_kb\" data-id=\"846\">multilingual templates<\/a>. Other examples are custom messages that only need to be sent to particular leasers, or that are dependent on motorization type of a vehicle. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example 1: Show message if particular leasing company<\/h2>\n\n\n\n<p>In this example, we only show a message if the leaser is <em>CBC<\/em>. Note that the parameter must be available to the workflow. <\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>{% if leaser_name == &#8216;CBC&#8217; %} Please add the employee number {{driver.client_employee_no}} to the contract reference column in your systems.<br>{% endif %}<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">Example 2: Show message based on motorization type<\/h2>\n\n\n\n<p>In the following example, we show the user a message depending on the motor type. For electric vehicles, we lead the user to a survey about charging. For combution engines, we send them to an article about ecological driving. <\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>{% if vehicle.motor_type == &#8216;Electric&#8217; %} Please fill out our <span style=\"text-decoration: underline;\">survey on charging infrastructure<\/span>.<br>{% elif vehicle.motor_type == &#8216;PHEV&#8217; %} Please contact john@example.com to pick up your smart charging cable. <br>{% else %} In <span style=\"text-decoration: underline;\">this blogpost<\/span>, you can find some best practices for ecological driving. <br>{% endif %}<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Headlight workflows support condition components, which allow you to branch your workflow off into different directions. However, this is not the only way to implement conditions into your workflows. For smaller scale conditions, such as message personalizations, you can use conditions directly in the body of text in your workflow&#8230;.<\/p>\n","protected":false},"author":2,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":[],"ht-kb-category":[94],"ht-kb-tag":[],"_links":{"self":[{"href":"https:\/\/www.help.headlight.tech\/index.php?rest_route=\/wp\/v2\/ht-kb\/852"}],"collection":[{"href":"https:\/\/www.help.headlight.tech\/index.php?rest_route=\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.help.headlight.tech\/index.php?rest_route=\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.help.headlight.tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.help.headlight.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=852"}],"version-history":[{"count":2,"href":"https:\/\/www.help.headlight.tech\/index.php?rest_route=\/wp\/v2\/ht-kb\/852\/revisions"}],"predecessor-version":[{"id":872,"href":"https:\/\/www.help.headlight.tech\/index.php?rest_route=\/wp\/v2\/ht-kb\/852\/revisions\/872"}],"wp:attachment":[{"href":"https:\/\/www.help.headlight.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=852"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.help.headlight.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fht-kb-category&post=852"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.help.headlight.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fht-kb-tag&post=852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}