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

cannot compare strings in macros #502

Closed
yatesco opened this issue Jun 24, 2021 · 5 comments
Closed

cannot compare strings in macros #502

yatesco opened this issue Jun 24, 2021 · 5 comments

Comments

@yatesco
Copy link

yatesco commented Jun 24, 2021

Hi - I have a macro which accepts a string argument but when I try and compare it I get "can't compare &str with str:

{% macro heading(title, sort) %}

<th class="tableHeaderSort">
  {{ title|e }}
  <span class={% if sort == "descending" %} "descending selected" {% else %} "descending" {% endif %}></span>
  <span class={% if sort == "ascending" %} "ascending selected" {% else %} "ascending" {% endif %}>

  </span>
</th>

{% endmacro %}

{% call heading("Closed", "ascending") %}

I've read #376 which I think suggest that this should work.

Any help is gratefully appreciated! Thanks

@djc
Copy link
Owner

djc commented Jun 24, 2021

Does this work outside a macro context?

@yatesco
Copy link
Author

yatesco commented Jun 25, 2021

Yes it does.

I didn't realise I could put rust code right inside the template so using enums instead of Strings works fine in macros:

{% macro heading(title, sort) %}
<th class="tableHeaderSort">
  {{ title|e }} {% match sort %} {% when SortBy::Descending %}
  <span class="descending selected"></span>
  <span class="ascending"></span>
  {% when SortBy::Ascending %}
  <span class="descending"></span>
  <span class="ascending selected"></span>

  {% when SortBy::None %}
  <span class="descending"></span>
  <span class="ascending"></span>

  {% endmatch %}
</th>
{% endmacro %}

{% call heading("Closed", SortBy::None) %}

(and yes, using Option<SortBy> is an upgrade from here :-))

@vallentin
Copy link
Collaborator

This should be fixed, but not released yet. Could you try and verify using the repo? :)

Like this:

[dependencies]
askama = { git = "https://github.com/djc/askama", rev = "017b590" }

@yatesco
Copy link
Author

yatesco commented Jun 25, 2021

@vallentin - Yes, it works fine against that revision :-)

@vallentin
Copy link
Collaborator

Great! If that was all, then I'll close this issue, as it's been fixed and will be included in the next release :)

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

3 participants