What is the purpose of {{ . }} in YAML?

huangapple go评论90阅读模式
英文:

What is the purpose of {{ . }} in YAML?

问题

我知道{{ }}用于评估表达式。但在Helm charts中,{{ . }}具体表示什么意思呢?

示例:

imagePullSecrets:
      {{- range .Values.image.pullSecrets }}
        - name: {{ . }}
英文:

I know that {{ }} is used to evaluate expressions. But what does specifically {{ . }} mean in Helm charts?

Example:

imagePullSecrets:
      {{- range .Values.image.pullSecrets }}
        - name: {{ . }}

答案1

得分: 1

你的问题不是关于YAML的,而是关于Go模板

在Go模板中,{{ }}用于评估表达式,而.是指向光标的引用。在你的示例中,光标由range设置,它会为pullSecrets中的每个元素评估其主体,并且在每次评估中,光标都会设置为当前元素。

Helm使用Go模板对YAML输入进行预处理。这与YAML本身无关。

英文:

Your question is not about YAML, it is about Go templates.

In Go templates, {{ }} evaluates expressions and . is the reference to the cursor. In your example, the cursor is set by range, which evaluates its body for each element in pullSecrets, and in each evaluation the cursor is set to the current element.

Helm uses Go templates to preprocess YAML input. This has nothing to do with YAML itself.

huangapple
  • 本文由 发表于 2021年7月21日 21:21:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/68470303.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定