-
Notifications
You must be signed in to change notification settings - Fork 301
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 a way to partially render a template (ignore missing variables in context) #962
Comments
That's not going to be built in but you can probably write your own filter to handle that |
Is there a reason for this? Do you need help with the implementation?
I suppose it'll require the following syntax |
It's an important feature of Tera to error if it's missing things rather than silently ignoring it.
You can also have it as a function eg, |
I didn't mean that the current behavior should be replaced. There should be a way to optionally ignore or tolerate the errors
Will try it, thanks. But anyway it doesn't look like an easy-to-use format for the end user who just wants to use a variable |
@Keats Added a Proof-of-Concept implementation of what we approximately need master...minev-dev:tera:master What do you think about investing some time into a well-shaped implementation? Or can you please give me recommendations on how I can properly implement it so I'll submit a PR? |
No that won't be added |
Problem
There is no way to partially render a template with the only variables available in a context and ignore the template variables that are not presented in the context.
Currently the
Processor::render
returns an error if at least one variable is failed to rendertera/src/renderer/processor.rs
Lines 1058 to 1062 in ae13d7c
Context
We have a multi-step rendering where not all the variables are available at the same time. There is a config file which should support system env variables injection (first step) and then cross-services variables injection in runtime (second step).
Here is a draft PR with the implementation and failing unit test opencloudtool/opencloudtool@20ae6de
Expected behavior
Initial template
First step
Context
Rendered template
Second step
Context
Rendered template
The text was updated successfully, but these errors were encountered: