I need to use text/template to template a file over successive iterations. Initially not all data values will be present but on later iterations more and more data values will exist.
Currently, values not found in the data supplied to Template.Execute() are replaced depending on the active option (set via Template.Option()). By default the following template:
ID={{ .Id }}, Name={{ .Name }}
will be templated as:
if executed with
data := map[string]interface{}{
"Name": "Bob",
}
But I need it to return:
Proposal
Adding a 'missingkey=ignore' option that would preserve the original tag in templated output if keys are missing from the data supplied when executing a template. I.e. the above template would return:
if executed with
data := map[string]interface{}{
"Name": "Bob",
}
This is a duplicate of #23488 but with a different use case.
I need to use
text/templateto template a file over successive iterations. Initially not all data values will be present but on later iterations more and more data values will exist.Currently, values not found in the data supplied to
Template.Execute()are replaced depending on the active option (set viaTemplate.Option()). By default the following template:will be templated as:
if executed with
But I need it to return:
Proposal
Adding a 'missingkey=ignore' option that would preserve the original tag in templated output if keys are missing from the data supplied when executing a template. I.e. the above template would return:
if executed with
This is a duplicate of #23488 but with a different use case.