YAML引用另一个文件中的另一个变量

Dmi*_*tri 5 string yaml reference transclusion

假设我有2个YAML文件:

1)application.yml

en:
  variable: "Hello World"
Run Code Online (Sandbox Code Playgroud)

2)user.yml

en:
  variable: <Here I want to get value from application.yml -> "Hello World" >
Run Code Online (Sandbox Code Playgroud)

起初我虽然可以使用引用:

1)application.yml

en:
  variable: &variable "Hello World"
Run Code Online (Sandbox Code Playgroud)

2)user.yml

en:
  variable: *variable
Run Code Online (Sandbox Code Playgroud)

但事实证明,只有在一个文件中声明的项目才有可能.有什么办法可以从application.yml中定义的变量中获取值吗?

Pau*_*tte 6

所以唯一的方法是创建另一个可以保存共享值的第三个文件.或者使用"application.yml"中的值.

YAML引用是文件内的.

您还可以在预处理步骤中合并YAML文件.

在*nix shell中:

cat foo.yaml bar.yaml > baz.yaml
Run Code Online (Sandbox Code Playgroud)

在Powershell中:

cat foo.yaml, bar.yaml > baz.yaml
Run Code Online (Sandbox Code Playgroud)

批量:

type foo.yaml bar.yaml > baz.yaml
Run Code Online (Sandbox Code Playgroud)

参考

  • 我添加了一些使用各种语言进行合并的方法. (2认同)