0

Say I have yaml data like so :

  fruit:
    - apple: 
      - color: "green"
      - taste: "bitter"
    - banana: 
      - color: "yellow"
      - taste: "sweet"

I would like to parse the list so as to get the printed result :

apple

banana

Is there some way to write a liquid template to achieve said result, without modifying my yaml data (because of course it could be fixed by changing it to name: "banana" and so on...)

{% for item in page.fruit %}
{{ item.?????? }}
{% endfor %}

Cheers

marsupilam
  • 127
  • 2
  • 7
  • Right, actually all these concepts, semantics and notations : hashes, the => in the outpout of {{ page.fruit }} and so on, are directly inherited from Ruby. But, AFAIK, this is not made explicit in the documentation of Jekyll or Liquid ! – marsupilam Jul 11 '16 at 16:27
  • Agree. That's why having your question as a duplicate [would be good](http://blog.stackoverflow.com/2010/11/dr-strangedupe-or-how-i-learned-to-stop-worrying-and-love-duplication/), think of "duplicate" as alternate versions/wordings of a question. – approxiblue Jul 11 '16 at 16:46

1 Answers1

0

Ok I found the solution in the OP here. As the guy is noting, it is not particularly easy to guess as a newcomer to this train of (object-oriented ?) thought...

---
layout: default
title: qui l'eut cru ?
permalink: /fruits/
fruit:
  - apple: 
    - color: "green"
    - taste: "bitter"
  - banana: 
    - color: "yellow"
    - taste: "sweet"
---

{% for item in page.fruit %}
{% for browser in item %}
**root of the sublist:** {{browser[0]}}  
**contents of the sublist:** {{browser[1]}}  
{% endfor %}
{% endfor %}
marsupilam
  • 127
  • 2
  • 7