-
Notifications
You must be signed in to change notification settings - Fork 177
YAML Anchors
Anchors are an easy way to duplicate your content across your setup file. Use &
to make an anchor and *
to refer to it. You can only use them for dictionaries and values, not lists. The anchor needs to appear above your reference.
Anchor: &my_anchor
Anchor reference: *my_anchor
You designate an anchor with the &
character. The ampersand acts as a label, referred to with the *
character.
safe_room: &my_safe_room 1234
crossing_training_sorcery_room: *my_safe_room
outfitting_room: *my_safe_room
The next time you update your safe_room
, you don't have to update the other settings that refer to it!
You can use anchors to merge a dictionary into another.
A dictionary looks like this:
waggle_sets:
spell_set1:
spell_set2:
an_empty_set_of_spells:
You can put attributes in dictionaries. Attributes: name: Shadow
noun: Moon
book: true
attributes_have_a: value
buff_spells:
spell_1:
mana: 12
spell_2:
mana: 3
abbrev: spell2
an_entry:
in_a_dictionary: true
You can put anchors infront of those spells
buff_spells:
spell_1: &anchor1
mana: 12
spell_2: &another_anchor
mana: 3
abbrev: spell2
You can refer to those spells via the anchors.
waggle_sets:
spell_set1:
<< : *anchor1
spell_set2:
<< : *another_anchor
<< : *anchor1
Some_other_spell:
mana: 1
abbrev: SoS
The above expands into:
waggle_sets:
spell_set1:
spell_1: &anchor1
mana: 12
spell_set2:
spell_2: &another_anchor
mana: 3
abbrev: spell2
<< : *anchor1
Some_other_spell:
mana: 1
abbrev: SoS
reviews:
<< : *pizza_review
chicago_hotdogs:
has_ketchup: unacceptable
without_ketchup: acceptable
stereotype: true