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

Optional fields support #291

Open
WieserSoftware opened this issue May 29, 2020 · 1 comment
Open

Optional fields support #291

WieserSoftware opened this issue May 29, 2020 · 1 comment
Labels

Comments

@WieserSoftware
Copy link

WieserSoftware commented May 29, 2020

Currently, I have a structure that has optional fields defined.

If the structure does not have the field, the template library currently outputs the name of the field.

I can get around that by using the GlobalSettings like this.
GlobalSettings.getUndefinedFieldValueSubstitutionString = (s) => 'OOPS';

Which will correctly substitute OOPS. However, if I replace oops with '' (the empty string), it reverts to showing the template (presumably because of not checking === undefined).

Is there a way to tell the template language not to care?

Maybe a reference like ${must.be.present.until.here?} or
${may?.be?.completely?.missing?}

@WieserSoftware
Copy link
Author

As a workaround, to hide the values in a template, you can use $when on an object:

"$when": "${exists(path.to.something)}"

Or if you're in building say markdown, and condionally want nothing, use
${if(exists(path.to.something), path.to.something, '')}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants