YAML setting value from another key
Asked Answered
P

2

6

How can I set a value in YAML from another key e.g:

example.emails:
     - [email protected]
     - [email protected]
     - [email protected]

swift:
        to_email:   example.emails
Prothorax answered 9/3, 2013 at 14:46 Comment(1)
do you mean relational tree?Adrien
P
-1

Ohh found the answer, just could not seem to find good documentation from Google :S

example.emails: 
     - [email protected] 
     - [email protected] 
     - [email protected] 

swift: 
      to_email: "%example.emails%"
Prothorax answered 9/3, 2013 at 14:53 Comment(4)
I can't tell what this answer actually means. What do the percents (%) do? Does this interpolate somehow? A full example would be greatly appreciated.Environs
This is still really unclear to me. An additional example, an demonstration of the result, or a link to the docs where you figured this out would be great.Colcothar
There is nothing in the YAML specification that describes that anything special needs to be done while/after loading this example. If PHP / Synfony does somethings special with "%example.emails%" that might be so, but that has nothing to do with the question.Intrauterine
That won't work until example.emails is placed as a parameterJohnathon
K
2

Accepted answer is wrong. It might have worked for the author for app specific reason but it is not supported by YAML specs. The correct way to reuse values in yaml is through something called anchors, like this

x1: &my_anchor
  y: 'my val'
x2:
  <<: *my_anchor
  z: 3

In above, we mark the values in x1 using anchor my_anchor. Then the special syntax <<: *my_anchor tells YAML parser to insert children of the node (in this case y) in the same level. So x2 will now have two children: y and z.

Kinin answered 29/12, 2019 at 7:39 Comment(0)
P
-1

Ohh found the answer, just could not seem to find good documentation from Google :S

example.emails: 
     - [email protected] 
     - [email protected] 
     - [email protected] 

swift: 
      to_email: "%example.emails%"
Prothorax answered 9/3, 2013 at 14:53 Comment(4)
I can't tell what this answer actually means. What do the percents (%) do? Does this interpolate somehow? A full example would be greatly appreciated.Environs
This is still really unclear to me. An additional example, an demonstration of the result, or a link to the docs where you figured this out would be great.Colcothar
There is nothing in the YAML specification that describes that anything special needs to be done while/after loading this example. If PHP / Synfony does somethings special with "%example.emails%" that might be so, but that has nothing to do with the question.Intrauterine
That won't work until example.emails is placed as a parameterJohnathon

© 2022 - 2024 — McMap. All rights reserved.