Skip to content
On this page

Reusable YAML Variables ‚Äč

Did you know you can reuse YAML code?

There are two parts to this:

  • The anchor & which defines the value of the variable
  • The alias * used to refer to the variable
yaml
title: &title 'Reusable YAML Variables'
description: &description 'Reusing YAML variables within grey matter to conveniently generate meta tags.'
meta:
  - name: og:description
    content: *description
  - name: og:title
    content: *title

This will now provide the title and description values throughout the YAML file.

While working with YAML and Grey Matter, I found this very convenient and figured I'd share.