<p>The problem is that you are setting <code>career</code> <strong>inside of</strong> the <code>if</code> statement. Defining it there won't make it available for your <code>elseif</code> statement.</p>

<p>I've trimmed down your code so you can see exactly what the problem is:</p>

<pre><code>{% set entries = ... %}

{% if entries|length &gt; 0 %}

    {% set career = ... %}

{% elseif career %}

    ...

{% endif %}
</code></pre>

<p>If you want <code>career</code> to be available to your <code>elseif</code> statement, you need to define it <strong>before</strong> your <code>if</code> statement.</p>

CC BY-SA 3.0
2015-03-19T18:42:01.597Z
I was considering that, but didn't performed it. Thank  you @Lindsey D
Dominik Krulak
CC BY-SA 3.0
2015-03-19T18:48:32.283Z
You are welcome! I was reviewing the edit history for your question, and noticed that Brad added indentation to your code example. I'm not sure if your original code also lacks indentation... Seeing it fully indented helped me find exactly where the error was. :)
Lindsey D
CC BY-SA 3.0
2015-03-19T18:37:50.300Z
2015-03-19T18:37:50.300Z
Lindsey D
<p>I get "Variable <code>career</code> does not exist". I'll just go straight to the code example...</p>

<pre><code>{# Set ECM and get the entries stored in variable "entries" #}
{% set entries = craft.entries.getAllSections('and, not career').type('news').order('RAND()').limit(3) %}

{# Conditional statement - if more entries than 0, we output them. If false, we set other conditional statement/s. #}
{% if entries|length &gt; 0 %}

    {# Loop through entries #}
    {% for entry in entries %}      
        &lt;li&gt;
            {# My Stuff #}
        &lt;/li&gt;
    {% endfor %}

    {# Set ECM and get the entries stored in variable "career" #}
    {% set career = craft.entries.section('career').type('news') %}

{% elseif career %}

    {# Loop through career #}
    {% for career in career %}      
        &lt;li&gt;
            {# My Stuff #}
        &lt;/li&gt;
    {% endfor %}

{% endif %}
</code></pre>

<p>Is it because of the first variable <code>entries</code>?</p>

CC BY-SA 3.0
2015-03-19T17:31:51.773Z
I don't understand the question... what variable doesn't exist? What's not working as you'd expect?
Brad Bell
CC BY-SA 3.0
2015-03-19T18:18:20.720Z
I expect to load `{% elseif career %}` if, the first statement is `false`. But variable `career` doesn't exists.
Dominik Krulak
CC BY-SA 3.0
2015-03-19T21:15:50.460Z
@Brad Bell Thank you for clean up and indentation!
Dominik Krulak
<variable><error>
Variable doesn't exist
# Variable doesn't exist

(Asked by: username_0 on 2015-03-19)

I get "Variable career does not exist". I'll just go straight to the code example...
{# Set ECM and get the entries stored in variable "entries" #}
{% set entries = craft.entries.getAllSections('and, not career').type('news').order('RAND()').limit(3) %}

{# Conditional statement - if more entries than 0, we output them. If false, we set other conditional statement/s. #}
{% if entries|length > 0 %}

    {# Loop through entries #}
    {% for entry in entries %}      
        
            {# My Stuff #}
        
    {% endfor %}

    {# Set ECM and get the entries stored in variable "career" #}
    {% set career = craft.entries.section('career').type('news') %}

{% elseif career %}

    {# Loop through career #}
    {% for career in career %}      
        
            {# My Stuff #}
        
    {% endfor %}

{% endif %}

Is it because of the first variable entries?

**Tags:** variable, error
> **Comments:**
> **username_1**: I don't understand the question... what variable doesn't exist? What's not working as you'd expect?  
> **username_0**: I expect to load `{% elseif career %}` if, the first statement is `false`. But variable `career` doesn't exists.  
> **username_0**: @Brad Bell Thank you for clean up and indentation!  

---

## 1 answers

### Answer by username_2 on 2015-03-19. Score: 2 | Accepted answer

The problem is that you are setting career inside of the if statement. Defining it there won't make it available for your elseif statement.
I've trimmed down your code so you can see exactly what the problem is:
{% set entries = ... %}

{% if entries|length > 0 %}

    {% set career = ... %}

{% elseif career %}

    ...

{% endif %}

If you want career to be available to your elseif statement, you need to define it before your if statement.

> **Comments:**
> **username_0**: I was considering that, but didn't performed it. Thank  you @Lindsey D  
> **username_2**: You are welcome! I was reviewing the edit history for your question, and noticed that Brad added indentation to your code example. I'm not sure if your original code also lacks indentation... Seeing it fully indented helped me find exactly where the error was. :)  

---

