1. Home
  2. Workflows
  3. How can I add specific conditions inside of a workflow component message?

How can I add specific conditions inside of a workflow component message?

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 their references. You can also create conditions based on parameters.

Concretely, you can add conditions using the following structure

{% if exampleTest %} Text if exampleTest is true
{% elif exampleTest2 %} Text if exampleTest2 is true
{% else %} Fallback result if none of the other conditions were true
{% endif %}

An example use case for this is multilingual templates. Other examples are custom messages that only need to be sent to particular leasers, or that are dependent on motorization type of a vehicle.

Example 1: Show message if particular leasing company

In this example, we only show a message if the leaser is CBC. Note that the parameter must be available to the workflow.

{% if leaser_name == ‘CBC’ %} Please add the employee number {{driver.client_employee_no}} to the contract reference column in your systems.
{% endif %}

Example 2: Show message based on motorization type

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.

{% if vehicle.motor_type == ‘Electric’ %} Please fill out our survey on charging infrastructure.
{% elif vehicle.motor_type == ‘PHEV’ %} Please contact john@example.com to pick up your smart charging cable.
{% else %} In this blogpost, you can find some best practices for ecological driving.
{% endif %}

Was this article helpful?

Related Articles

Leave a Comment