Cody Bontecou

Reusable YAML Variables

January 29, 2023 · 1 minute read · yaml,frontmatter

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
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.

Newsletter

Subscribe to get my latest content. No spam.