Home > Backend Development > Golang > 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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2024-02-11 09:30:17
forward
802 people have browsed it

将整个 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:
Copy after login

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 of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template