Template apply_fields - how to ignore a field with default value

Hi,

I have a template string that defines an optional field. However that optional field has a default value.
There are times when I’m using apply_fields on a template but I do not want this optional field. I leave the key out of the fields I’m applying but the default option plugs it back in anyway.
Is there a way to for apply_fields to ignore a default option? This field needs a default option for other purposes in the pipeline.

Thanks!

4 Likes

Hey, good question. It’s one I’ve seen come up before in support.

As you say if a template key has a default value, then it’s essentially always provided so it can’t be optional. There is no way to say don’t apply the default value on a key when resolving the path.

The best thing to do here would be to use two different keys, one for when it can be optional, and one for the other scenarios where a default value should be applied.

Best
Phil

2 Likes

That’s sort of my work around. Just provide two different values.
Might be something to suggest as a feature. Add an argument to ignore defaults in apply_fields.

Thanks!

2 Likes

I’ve submitted an idea on your behalf on our roadmap page!

(Note you won’t see it there as suggestions are kept internally)

2 Likes