Home  >  Article  >  Backend Development  >  Pass the entire yaml from value to template without populating empty fields with null

Pass the entire yaml from value to template without populating empty fields with null

WBOY
WBOYforward
2024-02-11 09:30:17673browse

将整个 yaml 从值传递到模板,而不用 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!

Question content

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":

65bdff7ed5February

Is there any way to prevent this from happening?

I am expecting the correct template without inserting empty fields.

Solution

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!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete