Skip to content

Ternary operator #2033

@paulshryock

Description

@paulshryock
  • AS A software engineer writing a Liquid template,
  • I WANT TO use a ternary operator to assign values for truthy or falsey scenarios,
  • SO THAT I can write this in one line instead of five.
- {% if url == "/" %}
-   {% assign my_variable = "something" %}
- {% else %}
-   {% assign my_variable = "something_else" %}
- {% endif %}
+ {% assign my_variable = url == "/" ? "something" : "something_else" %}

There is a huge amount of support for this crucial feature in twelve-year-old issue #236.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions