1

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 %}      
        <li>
            {# My Stuff #}
        </li>
    {% 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 %}      
        <li>
            {# My Stuff #}
        </li>
    {% endfor %}

{% endif %}

Is it because of the first variable entries?

  • 1
    I don't understand the question... what variable doesn't exist? What's not working as you'd expect? – Brad Bell Mar 19 '15 at 17:31
  • I expect to load {% elseif career %} if, the first statement is false. But variable career doesn't exists. – Dominik Krulak Mar 19 '15 at 18:18
  • @Brad Bell Thank you for clean up and indentation! – Dominik Krulak Mar 19 '15 at 21:15
2

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.

|improve this answer|||||
  • I was considering that, but didn't performed it. Thank you @Lindsey D – Dominik Krulak Mar 19 '15 at 18:42
  • 1
    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 Mar 19 '15 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.