Unexpected ENDIF

What is wrong in this code? Thank you for information.

Unexpected ENDIF in .. on line 7

        {% set robots = ['1': ['1': 'Voltron', '2': 'Astro Boy'], '2': ['1': 'VoltronBlaBla', '2': 'Astro Boy Bla Bla']] %}

{% if 1 %} {% for key, val in robots %} {% for key2, val2 in val %} {% endfor %} {% endfor %} {% elseif 2 %} {% endif %}

edited Sep '16

You have elseif which does nothing. Just remove it.

       {% set robots = ['1': ['1': 'Voltron', '2': 'Astro Boy'], '2': ['1': 'VoltronBlaBla', '2': 'Astro Boy Bla Bla']] %}
      {% if 1 %}
          {% for key, val in robots %}
              {% for key2, val2 in val %}
              {% endfor %}
          {% endfor %}
      {% endif %}


209

but i need elseif, this code is only for example to show error

OKAY, that's different if you have actual content.

You have syntax error, some unescaped chars perhaps -{ or %? Post your full code sample.



209

I need generate select. If type=1 my select must be optgroup, if type=2 not. For example:

<select>
    <optgroup label="Swedish Cars">
        <option value="volvo">Volvo</option>
        <option value="saab">Saab</option>
    </optgroup>
    <optgroup label="German Cars">
        <option value="mercedes">Mercedes</option>
        <option value="audi">Audi</option>
    </optgroup>
</select> 

and I have variable and table (for example of course):

{% set type = 1 %}
{% set cars = ['Swedish Cars': ['1': 'Volvo', '2': 'Saab'], 'German Cars': ['1': 'Mercedes', '2': 'Audi']] %}

<select>
{% if type==1 %}
    {% for key, val in cars %}
    <optgroup label="{{ key }}">
        {% for key2, val2 in val %}
        <option value="{{ key2 }}">{{ val2 }}</option>
        {% endfor %}
    </optgroup>
    {% endfor %}
{% elseif type==2 %}
    {% for key, val in cars %}
        {% for key2, val2 in val %}
        <option value="{{ key2 }}">{{ val2 }}</option>
        {% endfor %}
    {% endfor %}
{% endif %}
</select>

I can fix it, ex:

<select>
{% if type==1 %}
    {% for key, val in cars %}
    <optgroup label="{{ key }}">
        {% for key2, val2 in val %}
        <option value="{{ key2 }}">{{ val2 }}</option>
        {% endfor %}
    </optgroup>
    {% endfor %}
{% endif %}
{% if type==2 %}
    {% for key, val in cars %}
        {% for key2, val2 in val %}
        <option value="{{ key2 }}">{{ val2 }}</option>
        {% endfor %}
    {% endfor %}
{% endif %}
</select>

but what is wrong with elseif?