Anchors & Aliases

7 min read · Beginner
You will learn
  • 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

What you write:
# Base configuration (the template)
base_config: &base_settings
technology: "28nm"
voltage: 1.2
temperature: 25
 
# Development environment
development:
<<: *base_settings
debug_mode: true
waveform_dump: true
 
# Production environment
production:
<<: *base_settings
debug_mode: false
optimization_level: "high"
Click Next to start
The left side shows what you write. The right side shows what YAML actually creates after resolving the template.
Anchors let you write settings once and reuse them in multiple places. Click Next to see how.

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:

# Create a template using & (ampersand)
base_config: &base_settings
·· technology: "28nm"
·· voltage: 1.2
·· temperature: 25
· = one space

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:

# Use the template with << and *
development:
·· <<: *base_settings # Copies all base settings here
·· debug_mode: true # Add extra settings
· = one space

What this means:

  • &base_settings creates a template called “base_settings”
  • <<: *base_settings copies 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:

# Base configuration
base_config: &base_settings
·· technology: "28nm"
·· voltage: 1.2
·· temperature: 25
# Development environment
development:
·· <<: *base_settings
·· debug_mode: true
·· coverage_enabled: true
·· simulation_time: 1000 # microseconds
·· waveform_dump: true
# Production environment
production:
·· <<: *base_settings
·· debug_mode: false
·· simulation_time: 10000 # microseconds
·· optimization_level: "high"
# Testing environment
testing:
·· <<: *base_settings
·· debug_mode: true
·· stress_testing: true
·· corner_analysis: true
· = one space

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

Q What does & do?
Q What does * do?
Q What does << do?
Q Can I override a value from the template?
Q What happens if I change the template?

Key takeaways

  • &name creates an anchor (template) you can reuse
  • <<: *name copies 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)