Escape |-character in Askama

Hello

I am trying to use Rust-code in Askama... Take for example this:

{% if restaurant.opening_hours.as_ref().unwrap().iter().find(|x| x.is_day(day.to_string())) %}

This gives the following parsing error:

error: problems parsing template source at row 139, column 92 near:
       "(|x| x.is_day(day.to_string())) %}\n     "...

I think this is because of the |-character. Is there a way to escape this in Askama?

I'm not familiar with Askama but it looks like closures aren't supported (yet).

This is going even further out on a limb (since I have no idea what is possible), but for this particular case maybe you could build an iterator of (xs, copies_of_day) and have a function

fn is_xs_day(tuple: (&Whatever, &DaysType)) -> bool {
    tuple.0.is_day(tuple.1.to_string())
}

And then put that in the find:

{% if restaurant
    .opening_hours
    .as_ref()
    .unwrap()
    .iter()
    .zip(std::iter::repeat(day))
    .find(is_xs_day)
%}
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.