String interpolation in YAML

Clinton picture Clinton · Apr 3, 2013 · Viewed 30.8k times · Source

In Perl I can do something like the following:

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

Can I do something like the following in YAML:

Home: /home
Alice: $Home/alice

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

Answer

Paul Fioravanti picture Paul Fioravanti · Apr 3, 2013

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' 

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