Search code examples
twigyamlgrav

YAML list of text/url pairs to be used in Grav/Twig


I would like to represent the following JSON structure in YAML.

[ 
    {'text': 'Text1', 'url': 'Url1'},
    {'text': 'Text2', 'url': 'Url2'},
    {'text': 'Text3', 'url': 'Url3'},
]

I have tried without success:

-
    text: Text1
    url: Url1
-
    text: Text2
    url: Url2
-
    text: Text3
    url: Url3

In case it might be relevant, the structure is going to be used in Grav/Twig, although I think it is a pure YAML issue.


Solution

  • Grav now provide two new filters for yaml-encoding and yaml-decoding. Example usage: {{ page.header.myarray|yaml_encode }}

    These filters will be available in the upcoming 1.4 release as per this commit: https://github.com/getgrav/grav/commit/c721be8787b09aab1dce6bd012c8d43d1a985558

    Hope it helps