# YAML Samples

## Single Document

### Data File

    ---
    key1: value1
    key2:
      - list item 1
      - list item 2
      - list item 3
    nested-list:
      - ['a', 'b', 'c']
      - ['A', 'B', 'C']
    mapping-series:
      - cola: a
        colb: b
        colc: c
      - cola: A
        colb: B
        colc: C

### Template File

    .. -*- mode: rst -*-

    Static Heading
    --------------

    Individual Item
    ~~~~~~~~~~~~~~~

    {{ data['key1'] }}

    List of Items
    ~~~~~~~~~~~~~

    {% for item in data['key2'] %}
    - {{item}}
    {% endfor %}

    Nested List Table
    ~~~~~~~~~~~~~~~~~

    Rendering a table from a list of nested sequences using hard-coded
    headers.

    {{ make_list_table(
        ['One', 'Two', 'Three'],
        data['nested-list'],
        title='Table from nested lists',
        ) }}

    Mapping Series Table
    ~~~~~~~~~~~~~~~~~~~~

    Rendering a table from a list of nested dictionaries using dynamic
    headers.

    {{ make_list_table_from_mappings(
        [('One', 'cola'), ('Two', 'colb'), ('Three', 'colc')],
        data['mapping-series'],
        title='Table from series of mappings',
        ) }}

### Loading the Template

    .. datatemplate:yaml:: sample.yaml
       :template: sample.tmpl

### Rendered Output

#### Static Heading

##### Individual Item

value1

##### List of Items

- list item 1

- list item 2

- list item 3

##### Nested List Table

Rendering a table from a list of nested sequences using hard-coded headers.

Table from nested lists
One | Two | Three
--- | --- | ---
a | b | c
A | B | C

##### Mapping Series Table

Rendering a table from a list of nested dictionaries using dynamic headers.

Table from series of mappings
One | Two | Three
--- | --- | ---
a | b | c
A | B | C

## Multiple Documents in One Source

### Data File

    ---
    key1: value1

    ---
    key: value
    key1: different value

### Template File

    .. -*- mode: rst -*-

    Static Heading
    --------------

    Individual Item
    ~~~~~~~~~~~~~~~

    {{ data[0]|tojson }}

    List of Items
    ~~~~~~~~~~~~~

    {% for item in data %}
    - {{item|tojson}}

      - {{item.key}}
      - {{item.key1}}
    {% endfor %}

    Mapping Series Table
    ~~~~~~~~~~~~~~~~~~~~

    Rendering a table from a list of nested dictionaries using dynamic
    headers.

    {{ make_list_table_from_mappings(
        [('Key', 'key'), ('Key One', 'key1')],
        data,
        title='Table from series of mappings',
        ) }}

### Loading the Template

    .. datatemplate:yaml:: sample-multiple.yaml
       :template: sample-multiple.tmpl
       :multiple-documents:

### Rendered Output

#### Static Heading

##### Individual Item

{“key1”: “value1”}

##### List of Items

- {“key1”: “value1”}

  - value1

- {“key”: “value”, “key1”: “different value”}

  - value

  - different value

##### Mapping Series Table

Rendering a table from a list of nested dictionaries using dynamic headers.

Table from series of mappings
Key | Key One
--- | ---
None | value1
value | different value