else condition does not work in my code in twig template
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 %}