Twig combined conditionals to set variable I am trying to check for the existence of a text field and an asset field and set an icon variable depending on the result.
I don't seem to be having much luck with defined, length and empty combinations.

Here's my code so far:

{% if (story.videoStoryUrl is defined) and (not story.storyImage | length) %}
    {% set icon = "video" %}
{% elseif (story.videoStoryUrl is empty) and (not story.storyImage | length) %}
    {% set icon = "text" %}
{% else %}
    {% set icon = "image" %}
{% endif %}


Any help appreciated :)
It's probably better if you set variables to reference, so your if statements make more sense.

{% set asset = story.storyImage.first() %}
{% set videoUrl = story.videoStoryUrl %}
{% set icon = "text" %}

{% if asset | length %}
    {% if videoUrl is empty %}
        {% set icon = "video" %}
     {% else %}
        {% set icon = "image" %}
    {% endif %}
{% endif %}

{{ icon }}