Grav – YAML Syntax

  • Post author:
  • Post category:Grav
  • Post comments:3 Comments
YAML

YAML stands for YAML Ain’t Markup Language which includes human readable content and often used in configuration files, blueprints (metadata information about resource) and page settings.

Features

Following are the features of YAML −

  • Compared to XML or JSON, YAML is less complex and provides same features.
  • It provides configuration settings without the need to learn complex code types such as CSS, JavaScript or PHP.
  • YAML describes data and content of the YAML file which can be easily translated to multiple language types.

Basic Rules of YAML

There are some basic rules of YAML which are used to reduce the ambiguity in multiple languages and editable programs.

  • You must end the YAML files with .yaml extension.
  • YAML must be case-sensitive.
  • YAML doesn’t support the use of tabs. Instead of tabs, it uses spaces which are not supported universally.

Basic Data Types of YAML

YAML supports some basic data types which can be used with programming languages such as −

  • Scalars − strings or numbers.
  • Sequences − arrays or lists.
  • Mappings − hashes or dictionaries.

Scalars

Scalars are the basic data types that use strings or numbers on the pages to work with the data. It may be a boolean property (either yes or no), integer value such as 2 or string of text such as word or sentence or title of the website.

For instance −

string: "Grav"
integer: 10
float: 10.5
boolean: true

Sometimes scalars come with unquoted values like integer, float or Boolean. The string value uses punctuation which comes with single or double quotation marks which uses escaping to specify ASCII and Unicode characters.

Sequences

YAML represent sequences in the form of arrays or lists. It defines each item with opening dash (-) placed in the list as shown below.

For instance −

- Apple
- Orange
- Grapes

Suppose if you want to define nested sequence with the sub items, and then place a single space before each dash in the sub items.

For instance −

-
   - Apple
   - Orange
   - Grapes

If you want nested sequence within the nested list, then add some levels as shown below −

For instance −

-
   -
      - Apple
      - Orange
      - Grapes

Mappings

It is a way of defining keys along with the values.

For example, you can assign some value to a specific element as −

Sports: cricket

Here the value is “cricket” that maps with the key called “Sports”. You can use this mapping with the sequence to specify the list of items for cricket; for example, we will define some player names for the value “cricket” making names as child and Sports: cricket as parent.

Sports: cricket
- Sachin Tendulkar
- Rahul Dravid
- M S Dhoni

Next Topic:-Click Here

This Post Has 3 Comments

Leave a Reply