Question

I can only find information about looping over associative arrays. However I want to access only the group key of the following lesson associative array to extract its value into my page. I've tried a number of syntaxes including dot notation: <li>{{ node.lesson.group }}</li> but that returns blank. I know the lesson associative array is present because when I use the syntax <li>{{ node.lesson }}</li> I get the output {"group"=>"intros", "position"=>1}

Following is an example of the front matter.

---
layout: page
title: "Control Structures 1"
lesson: 
 - 
  group: 'intros'
  position: 1
---
{% include JB/setup %}
Was it helpful?

Solution

This is one answer to the problem by using a mapfilter. Can anybody do better than this because it seems quite wordy.

<li>{{ node.lesson | map: 'group' }}</li>

(Note: It never fails - after 1 hour of trying various things I discover the answer minutes after posting the question.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top