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

Any configuration option to have the parser leave uncaptured variables unchanged? #603

Open
hugoqribeiro opened this issue Nov 16, 2023 · 4 comments

Comments

@hugoqribeiro
Copy link

I'm trying to find a way to configure the parser to leave such variables unmodified in the output...

Consider the following template:

Hello {{Name}}
Etc.

If we send a dictionary (as the model) only with the following value:

["Email"] = "XXX"

The output is:

Hello
Etc.

In our scenario, this error could go easily unnoticed, so we want to have the parser to leave {{Name}} unchanged...

Is it possible?

@drewburlingame
Copy link

We would find the same feature helpful in cases where we have a master template that can be partially rendered in one stage and then the remaining variables rendered in a following stage.

@sebastienros
Copy link
Owner

leave {{Name}} unchanged

{name} is a limited example, because it would be easy to provide a hook when a member is not defined to render warning, but how would you handle {name | uppercase}, or {% if name = 'eric' %}. So a direct substitution doesn't seem possible.

@drewburlingame looks like you want templates to generate templates, which technically is doable by rendering something that contains {name} and escaping the brackets.

@drewburlingame
Copy link

@sebastienros yeah that makes sense. Our situation is complicated by the fact that our customers are not aware of the different stages so they don't know which variables to escape.

In answer to your question about how to handle {name | uppercase}, we'd prefer the whole block to pass through. I can see how conditional statement will be more complicated to detect, especially if its checking for null. It would help if Fluid could distinguish between 'null' because key does not exist vs key exists and value null.

@sebastienros
Copy link
Owner

It would help if Fluid could distinguish between 'null' because key does not exist vs key exists and value null.

Correct. To be able to do that we need to change ValueTask<FluidValue> FluidValue.GetValueAsync(string name, TemplateContext context) to TryGetValueAsync to note that the member is not available (still return nil). The current nil value is no sufficient since it represents both null values and undefined ones. Or we'd need a custom undefined FluidValue inheriting from nil that would mean a member which doesn't exist. (Equivalent to false for TryGetValue).

Maybe something to do at the same time that the member accessors would be refactored to accept any property by default (not allow-listed by default like today).

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