Skip to content

Liquid: Nested if statements #284

Closed
Closed
@macdonaldr93

Description

@macdonaldr93

It looks like nested if statements are causing issues. It associates else to the first if rather than the second. This is just a snippet of the larger file.

Source

{% if cat != tag and cat_item == cat %}
  {% comment %}
    Curabitur vestibulum aliquam leo. Nam commodo suscipit quam
  {% endcomment %}
  {% if current_tags contains tag %}
    <li class="lorem-filter active-filter" data-group="{{ cat_item }}" data-handle="{{ tag | handle }}">{{ tag | remove_first: cat_item | remove_first: '_' | link_to_remove_tag: tag }}</li>
  {% else %}
    <li class="lorem-filter" data-group="{{ cat_item }}" data-handle="{{ tag | handle }}">{{ tag | remove_first: cat_item | remove_first: '_' | link_to_add_tag: tag }}</li>
  {% endif %}
{% endif %}

Output

{% if cat != tag and cat_item == cat %}
    {% comment %}
    Curabitur vestibulum aliquam leo. Nam commodo suscipit quam
    {% endcomment %}
    {% if current_tags contains tag %}
    <li
        class="lorem-filter active-filter"
        data-group="{{ cat_item }}"
        data-handle="{{ tag | handle }}">{{ tag | remove_first: cat_item | remove_first: '_' | link_to_remove_tag: tag }}</li>
{% else %}
    <li
        class="lorem-filter"
        data-group="{{ cat_item }}"
        data-handle="{{ tag | handle }}">{{ tag | remove_first: cat_item | remove_first: '_' | link_to_add_tag: tag }}</li>
{% endif %}
{% endif %}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions