YAML 中的字符串插值

问题描述:

在 Perl 中,我可以执行以下操作:

In Perl I can do something like the following:

my $home = "/home";
my $alice = "$home/alice";

我可以在 YAML 中执行以下操作吗:

Can I do something like the following in YAML:

Home: /home
Alice: $Home/alice

所以爱丽丝"到底是有效的/home/alice?

So "Alice" is effectively /home/alice in the end?

不幸的是,你运气不好.要执行您想要的操作,您需要从视图文件(或任何地方)传入 $home 并将其插入到您的 yaml 条目中,这可能类似于:

Unfortunately, you're out of luck. To do what you want you'd need to pass in $home from a view file (or wherever) and interpolate it in your yaml entry, which could possibly look something like:

Alice: ! '%{home}/Alice' 

请参阅此 StackOverflow 问答,了解您的问题的详细答案.

See this StackOverflow Q&A for the detailed answer to pretty much exactly your question.