AdaptiveCards icon indicating copy to clipboard operation
AdaptiveCards copied to clipboard

Optional fields support

Open WieserSoftware opened this issue 4 years ago • 1 comments

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 avatar May 29 '20 13:05 WieserSoftware

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, '')}

WieserSoftware avatar May 29 '20 14:05 WieserSoftware