Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we use filters in IF, FOR or CASE tags? #1567

Closed
QuanWanxx opened this issue Apr 15, 2022 · 2 comments
Closed

Can we use filters in IF, FOR or CASE tags? #1567

QuanWanxx opened this issue Apr 15, 2022 · 2 comments

Comments

@QuanWanxx
Copy link

QuanWanxx commented Apr 15, 2022

Hi,

From the Liquid wiki spec Liquid-For-Designers, the <CONDITION> in {% if <CONDITION> %} ... {% endif %} "should be either a normal Liquid expression or a comparison using Liquid expressions".

Does filters output belongs to Liquid expressions? For example, I want to directly check the condition using where filter in if, when exist products that "type" is "kitchen" then display.

{% if products | where: "type", "kitchen" %}
  Hello!
{% endif %}

This liquid example will always display as long as products is not empty, where takes no effects.

Am I must to assign the filters output to an variable, then can use it in if, for or case tags?

@dylanahsmith
Copy link
Contributor

Filters are only supported on a subset of tags (e.g. assign tag), which don't include if, for or case tags. A liquid expression refers to what would come before the pipe symbol in a variable tag (e.g. {{ some_expression | some_filters }}.

Using an assign tag is indeed the way this can be accomplished.

@QuanWanxx
Copy link
Author

Got it, thanks for your explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants