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

multiple comparisons possible? {% if config.extra.a and (config.extra.b or config.extra.c) %} #743

Closed
Jieiku opened this issue Aug 8, 2022 · 5 comments

Comments

@Jieiku
Copy link
Contributor

Jieiku commented Aug 8, 2022

multiple comparisons possible? {% if config.extra.a and (config.extra.b or config.extra.c) %}

I ask because this particular if statement is part of an if elif elif elif elif else endif

I am trying to parse options in a way that makes less configuration work for the end user.

There is probably a workaround I could do for this, but I have ran into this a couple times, but when I try to make a combination of comparisons it does not seem to work.

In this particular instance I was trying to do this:

{% if config.extra.js_bundle and config.build_search_index or config.extra.search_library %}

What I did instead was this:

{%- if config.build_search_index or config.extra.search_library %}
  {%- set searchYes = true %}
{%- endif %}

{%- if searchYes and config.extra.js_bundle %}
@Keats
Copy link
Owner

Keats commented Aug 8, 2022

What's the error? It should work

@Jieiku
Copy link
Contributor Author

Jieiku commented Aug 8, 2022

Thanks for the reply @Keats

Unless I have a mistake here, it treats the entire comparison as or instead of and or

What I am attempting to do is always require config.extra.js_bundle, but also must have either config.build_search_index or config.extra.search_library

If it helps I can setup a test case repo, just let me know.

2022-08-08_15-09-20

@Keats
Copy link
Owner

Keats commented Aug 8, 2022

It's doing {% if (config.extra.js_bundle and config.build_search_index) or config.extra.search_library %}

@Jieiku
Copy link
Contributor Author

Jieiku commented Aug 8, 2022

so does that mean I would rewrite it like this?

{%- if config.extra.js_bundle and config.build_search_index or config.extra.js_bundle and config.extra.search_library %}

Edit: yep so far that seems to work, thanks for the help!

@Keats
Copy link
Owner

Keats commented Aug 8, 2022

yep, and has higher precedence than or

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