Is there YAML syntax for sharing part of a list or map?

前端 未结 5 2163
猫巷女王i
猫巷女王i 2020-11-29 01:07

So, I know I can do something like this:

sitelist: &sites
  - www.foo.com
  - www.bar.com

anotherlist: *sites

And have sitelist<

5条回答
  •  执笔经年
    2020-11-29 01:28

    To piggyback off of Kittemon's answer, note that you can create mappings with null values using the alternative syntax

    foo:
        << : myanchor
        bar:
        baz:
    

    instead of the suggested syntax

    foo:
        << : myanchor
        ? bar
        ? baz
    

    Like Kittemon's suggestion, this will allow you to use references to anchors within the mapping and avoid the sequence issue. I found myself needing to do this after discovering that the Symfony Yaml component v2.4.4 doesn't recorgnize the ? bar syntax.

提交回复
热议问题