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

Template Render to keep unresolved variables as-is in the output #1046

Open
kasingal opened this issue Apr 12, 2023 · 4 comments
Open

Template Render to keep unresolved variables as-is in the output #1046

kasingal opened this issue Apr 12, 2023 · 4 comments

Comments

@kasingal
Copy link

kasingal commented Apr 12, 2023

I am interested in rendering a template in multiple steps or keeping the references for the undefined variables in Jinja2.
Basically not to set value as null for undefined/unresolved variables and keep references/variable as-is if they are missing in the context.

Example: Let's say context has only name = "test", and then redering the following template:
<p>{{name}} has {{quantity}}</p>

I expact the output as below:
<p>test has {{quantity}}</p>

but as of today, output looks like below:
<p>test has </p>

Does anyone know if this is achievable within current version, or it would need an additional configuration to be added ?

@marius-diumia
Copy link

marius-diumia commented May 20, 2023

Looks like this feature doesn't exists and I'm Interested as well on using it.
Pushed a PR for this: #1072

@jasmith-hs
Copy link
Contributor

jasmith-hs commented May 21, 2023

For simple cases, this can already be done with:

context.setDynamicVariableResolver(string -> "{{ " + string + " }}");

@marius-diumia
Copy link

Great @jasmith-hs, thank you. It does for now what I need. Checked, but it doesn't work when the token has filters to apply.

@kasingal
Copy link
Author

kasingal commented May 21, 2023

@jasmith-hs | @marius-diumia

Rather than complex solution, as a workaround I created a wrapper on JinjavaInterpreter and just override getAsString() method to not set empty string rather keep the context.currentNode.master.image as-is.

Refer: https://gerrit.onap.org/r/c/ccsdk/cds/+/134501/1/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt#130

This solution can be in original JinjavaInterpreter as a default behavior.

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

3 participants