Home >Backend Development >Golang >Pass the entire yaml from value to template without populating empty fields with null
In this article I will introduce an interesting trick of passing the entire YAML from value to template without using null to fill empty fields. This technique can improve the readability and maintainability of the code, while also reducing the amount of code. Through the explanation of this article, readers will understand how to use this technique and learn to apply it in their own projects. Let’s explore together!
I am trying to pass the given part of values.yaml into a helm template:
receivers: test1: test2: test3: test4:
Use function:
{{ .values.receivers | to yaml | nindent 2}}
The code is placed in the correct format, but empty fields are populated with "null":
65bdff7ed5FebruaryIs there any way to prevent this from happening?
I am expecting the correct template without inserting empty fields.
No fields were inserted. The processor simply replaces the already existing value with a different serialization with the same semantics.
test3:
without a value in the yaml is parsed as having an empty scalar value. yaml core architecture Define the following for null values: p>
Regular expression | Resolved to tag |
---|---|
null | Null | NULL | ~ |
tag:yaml.org,2002:null |
/* Empty */ |
tag:yaml.org,2002:null |
The above is the detailed content of Pass the entire yaml from value to template without populating empty fields with null. For more information, please follow other related articles on the PHP Chinese website!