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

Any way to do string comparison inside an if condition? #20

Closed
thecodrr opened this issue Jun 25, 2023 · 2 comments
Closed

Any way to do string comparison inside an if condition? #20

thecodrr opened this issue Jun 25, 2023 · 2 comments
Labels
question Further information is requested

Comments

@thecodrr
Copy link

Basically something like:

{% if site.config.theme  == "light" %}

{% else %}
    
{% endif %}
@rossmacarthur
Copy link
Owner

rossmacarthur commented Jun 26, 2023

Currently the upon way to do this is with a filter. For example:

engine.add_filter("eq", str::eq);

And then in your template

{% if site.config.theme | eq: "light" %}

{% else %}
    
{% endif %}

@rossmacarthur rossmacarthur added the question Further information is requested label Jun 26, 2023
@rossmacarthur
Copy link
Owner

rossmacarthur commented Jun 26, 2023

I do think == and != is a common enough operation that it is probably worth adding as a first class thing. I wanted to avoid adding stuff like + and - expressions because the templates get really complicated but I think boolean operators are probably fine.

I have opened #21 to track this

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

No branches or pull requests

2 participants