ansible - J2 template

Ansible question
I have a variable, let call it value1 and a J2 template.

The J2 template includes the following line :
LINE=” This string mut be included this string is optional= {{ value1}}”

What I need to implement

If value1 is defined with a string – let assume that the string is OK (Value1: OK)
, the file should be
LINE=” This string must be included this string is optional= OK”

If value1 is not defined (empty Value1: ) –the file should be
LINE=” This string must be included”

So how the J2 should be configured?

LINE=” This string must be included{% if value1 is defined %}
this string is optional= {{ value1 }}{% endif %}”

Test the variable is both defined and not empty,
e.g. (minimal version)

  {% if value1 is defined and value1|d('')|length > 0 %}
  {{ value1 }}
  {% else %}
  This string must be included
  {% endif %}