Anchors & Aliases
- How & creates an anchor (a reusable template block)
- How *name references an anchor and << merges its values
- How to keep a large config DRY — edit once, propagate everywhere
Sometimes you have the same settings that need to be used in multiple places. Instead of copying and pasting the same information over and over, YAML has a special feature called “anchors” and “references” that lets you reuse information.
Think of it like creating a template that you can copy to different places.
Watch how one template flows into three different environments:
Interactive: How Anchors & Aliases Work
Click Next — see the template being created, then watch it get copied into each environment
Step 1: Create an Anchor (Template)
You create a template using the & (ampersand) symbol. This “anchors” a set of values so you can reference them later:
The &base_settings after the colon creates a template called “base_settings.” The three values below it (technology, voltage, temperature) are now saved as a reusable template.
Step 2: Use the Template with References
You use the template with <<: and * (asterisk). This copies all the values from the template into a new section:
What this means:
&base_settingscreates a template called “base_settings”<<: *base_settingscopies all the items from that template- You can then add more items specific to each section
Using YAML for Different Environments
In semiconductor design, you often need different settings for development, production, and testing. All three environments share the same base settings (technology, voltage, temperature), but each adds its own extras.
Instead of writing the same three lines three times, you write them once and reference them:
All three environments automatically get technology: "28nm", voltage: 1.2, and temperature: 25 from the base template. Each one then adds its own specific settings.
If you ever need to change the technology from “28nm” to “7nm”, you change it in one place (the base template) and all three environments update automatically.
Common Questions
Key takeaways
- ✓
&namecreates an anchor (template) you can reuse - ✓
<<: *namecopies all values from the anchor into a new section - ✓ You can add extra settings on top of the template
- ✓ Change the template once → all references update automatically
- ✓ This prevents copy-paste errors and keeps your files DRY (Don’t Repeat Yourself)