else condition does not work in my code in twig template In the code given below

content.field_image_link[0]['#url'] 
is empty but it still enters the if condition and adds html
what is incorrect in the below code due to which it enters the if condition whereas it should enter the second if condition given below

{% if content.field_image_link[0]['#url'] %}

{% block paragraph %}    

 &lt;div{{ attributes.addClass(classes) }}&gt;

    {% block content %}    

{% if content.field_image_link[0]['#url'] %}

&lt;a href="{{ content.field_image_link[0]['#url'] }}"&gt;

{{ content.field_image_2 }}
&lt;/a&gt;       
&lt;h2&gt;
&lt;a href="{{ content.field_image_link[0]['#url'] }}"&gt;
{{ content.field_image_link[0]['#title'] }}
&lt;/a&gt;
&lt;/h2&gt;
{% endif %}
{% if content.field_image_link[0]['#url'] == '' %}
{{ content.field_image_2 }}
&lt;h2&gt;                                                                                                                                                                                                     
{{ content.field_image_link[0]['#title'] }}                                                                                                                                                               
&lt;/h2&gt;
{% endif %}
    {% endblock %}
  &lt;/div&gt;

{% endblock paragraph %}
You need to check if variable is defined (defined in twig) and additionally also check the length of variable in twig.

{% if content.field_image_link[0]['#url'] is defined and content.field_image_link[0]['#url'] | length &gt; 0 %}
    //do stuff
{% else %}
    //do another stuff
{% endif %}