Skip to content

YAML Basics

Peter Edwards edited this page Jul 7, 2021 · 2 revisions

The following piece of YAML illustrates the key syntax elements currently used in this theme:

---
# Employees
employees:
  - name:
      first: John
      last: Salter
    job: Developer
    skills:
      - python
      - perl
  - name:
      first: Peter
      last: Edwards
    job: Developer
    skills:
      - php
      - javascript
    address: |
      24 Barker Terrace
      Hebden Bridge
      HX7 5TQ

The first line is special and present in all YAML files - it contains three hyphens.

The second line is a comment (comments start with a hash # symbol).

The third line contains the key employees followed by a colon - this could be seen as a keyword used to refer to the following data structure (which is indented by two spaces). There are two items in the employees data structure - these are denoted by a hyphen followed by a space. The design of YAML is heavily dependent on spaces as a way of denoting structure - indentation is very important.

Each employee is defined as a series of keys containing data.

  • The first, name contains two labelled items, first and last, each of which contain text.
  • The second and simplest one is job - this just contains text.
  • The third, skills contains a list of items (again using indentation and a hyphen)
  • The fourth, address contains multiple lines of text. This is achieved using the pipe | symbol - note how each line of text is indented(!).

Complex data structures can be built using just these elements, and you will find examples throughout the theme.

Clone this wiki locally