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

default filter: make the value optionnal and add d alias #907

Open
nevermille opened this issue Apr 11, 2024 · 1 comment
Open

default filter: make the value optionnal and add d alias #907

nevermille opened this issue Apr 11, 2024 · 1 comment

Comments

@nevermille
Copy link

I have to manage lots of templates where I have to apply the default filter on every single variable. Today, I need to write |default(value=""). I won't ask for an auto-default because it already was discussed before, but would it be possible to make the filter more like what's in jinja to speed up the process?

Let's use this basic call as an example :

// Returns "Hello !"
Tera::one_off("Hello {{ name|default(value=\"\") }}!", &Context::default(), false);

First, make the value parameter optional and return an empty string if not present:

// Returns "Hello !"
Tera::one_off("Hello {{ name|default }}!", &Context::default(), false);

Second, add the d alias:

// Returns "Hello !"
Tera::one_off("Hello {{ name|d }}!", &Context::default(), false);
@Keats
Copy link
Owner

Keats commented Apr 14, 2024

v2 will allow you to do {{ name or "" }}, I don't think we'll change the default filter until then

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

2 participants