YAML 中的字符串插值 [英] String interpolation in YAML

查看:37
本文介绍了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.

这篇关于YAML 中的字符串插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆