Skip to content

Comparisons within assign #1102

@andymikulski

Description

@andymikulski

It appears that the assign operator doesn't like comparisons (i.e. [thing] contains [other thing]). For instance, I would expect this to work:

{%- assign is_some_product = variant.tags contains "example" -%}

But produces the error: Expected end_of_string but found comparison in [...]

I've used the following as a workaround:

{% if variant.tags contains "example" %}
  {%- assign is_some_product = true -%}
{% else %}
  {%- assign is_some_product = false -%}
{% endif %}

While the latter works, the former is much more concise and is what I would expect to work. Note that I found this while trying to use the or operator as well, but seeing as comparisons themselves aren't accepted, I don't think the parser even got that far.


edit 10/30/2020: The following snippet also works and is a bit more compact:

{%- assign is_some_product = false -%}
{% if variant.tags contains "example" %}
  {%- assign is_some_product = true -%}
{% endif %}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions