Answers.Body: <p>It's probably better if you set variables to reference, so your if statements make more sense.</p>
  
  <pre><code>{% 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 }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-24T07:30:14.837Z
Answers.Text: Thanks! - that almost works - changed if video url and removed empty. Interestingly, can you compare two variables in one 'if'?
Answers.UserDisplayName: joomkit
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-24T13:49:32.930Z
Answers.Text: Yes, it uses 'and' like you did above but my guess is the 'not' in your logic right after it is breaking it, so instead of complicating the if statement break it down to what you really want to display.
Answers.UserDisplayName: Xpertbot
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-24T03:40:41.280Z
Answers.LastActivityDate: 2016-03-24T03:40:41.280Z
Answers.UserDisplayName: Xpertbot
Body: <p>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.</p>
  
  <p>Here's my code so far:</p>
  
  <pre><code>{% 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 %}
  </code></pre>
  
  <p>Any help appreciated :)</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-23T23:02:11.133Z
Comments.Text: What do you want to happen here and what are the results you're seeing?
Comments.UserDisplayName: Brad Bell
Tags: <templating>
Title: Twig combined conditionals to set variable
ThreadText: # Twig combined conditionals to set variable
  
  (Asked by: username_0 on 2016-03-23)
  
  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 :)
  
  **Tags:** templating
  
  > **Comments:**
  > **username_1**: What do you want to happen here and what are the results you're seeing?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-03-24. Score: 5 | Accepted answer
  
  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 }}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks! - that almost works - changed if video url and removed empty. Interestingly, can you compare two variables in one 'if'?  
  > **username_2**: Yes, it uses 'and' like you did above but my guess is the 'not' in your logic right after it is breaking it, so instead of complicating the if statement break it down to what you really want to display.  
  
  ---
  
  