You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to call this filter by writing the filter indent_by::<2> in the Askama template (which is a stateless function).
Use-case
I am translating the Rule-Based approach for transformations in XLST to Rust. The idea is to code a function that takes an (XML) input and outputs another text format. Sometimes, this can be done by delegating the processing to the children. In light of #575, I implemented it as you suggested: having fields that are templates themselves. the result makes a lot of sense from the Rule-Based approach.
By using {{ child_template.render()?|safe }}, I can locate the children result in a template, but to have full control of the output, I need to indent it like this {{ child_template.render()?|indent_by::<X>|safe }}.
I could indent as a post-processing, but I lose a lot of control over the output.
Example
Note: I tried to come up with a minimal example, so I had to strip a few things.
We want to display a poem, written in XML, in HTML. The input is
<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><title>
Song
</title></head><body><article><h1>
Song
</h1><address>
Rupert Brooke
</address></article></body></html>
My approach is to have 3 templates: File, Title, and Author, where File delegates to the others to achieve a Rule-Based approach. These are the templates.
Yes! your solution totally works, sorry for not seeing it before. Also, there is already a indent built-in filter.
Would you consider expanding the Custom filters section of the book to indicate that filters can take extra arguments after the &str? (I can do a first draft if you want)
I have a custom filter that is naturally parametrized by a
usize
and I was hoping to implement it in a turbo-fish manner with aconst
parameter.My custom filter indents the string by prefixing a string, a number of times, to each line. The code is the following.
I would like to call this filter by writing the filter
indent_by::<2>
in the Askama template (which is a stateless function).Use-case
I am translating the Rule-Based approach for transformations in XLST to Rust. The idea is to code a function that takes an (XML) input and outputs another text format. Sometimes, this can be done by delegating the processing to the children. In light of #575, I implemented it as you suggested: having fields that are templates themselves. the result makes a lot of sense from the Rule-Based approach.
By using
{{ child_template.render()?|safe }}
, I can locate the children result in a template, but to have full control of the output, I need to indent it like this{{ child_template.render()?|indent_by::<X>|safe }}
.I could indent as a post-processing, but I lose a lot of control over the output.
Example
Note: I tried to come up with a minimal example, so I had to strip a few things.
We want to display a poem, written in XML, in HTML. The input is
The desired output is
My approach is to have 3 templates:
File
,Title
, andAuthor
, whereFile
delegates to the others to achieve a Rule-Based approach. These are the templates.In the Rust side, I would have the following code.
The text was updated successfully, but these errors were encountered: