-
Notifications
You must be signed in to change notification settings - Fork 169
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
Add filter to interpret a string early #570
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is more dangerous than the regular nested interpretation stuff but wanted to get @jasmith-hs thoughts on this as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea, just one change to make in the snippet to eliminate confusion
input = @JinjavaParam(value = "s", desc = "String to render", required = true), | ||
snippets = { | ||
@JinjavaSnippet( | ||
code = "{{ \"{% if my_val %}} Hello {% else %} world {% endif %}\"|render }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra }
after {% if my_val %}
|
||
@Test | ||
public void itWritesObjectAsString() { | ||
String stringToRender = "{% if null %}}Hello{% else %}world{% endif %}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra }
here too
This PR adds a new
RenderFilter
which can be used to interpret a template string early.For instance, the following:
would output
World
. However, you could use the result of the filter in other filters, like so:which would output
world
.This is useful in cases where a function or other construct results in an expression that must be interpreted before applying other filters / transformations.
I'm open to naming this something different if people don't like
render
.