2
votes

I can't seem to create an array with all the page titles in my Jekyll site. This is how I'm going about looping through the pages in liquid:

{% for page in site.pages %}
{% assign page_title_array = {{ page_title_array | append: page.title }} %}
{% endfor %}

{{ page_title_array }}

For example, I have the following page titles in my site: Alfa, Bravo, Charlie, Delta. If I run through the loop, the value in page_title_array is Bravo instead of all the page titles.

3

3 Answers

3
votes

Use the map filter for this case:

{% assign page_title_array = {{ site.pages | map: 'title' }} %}
0
votes

Create an empty array :

{% assign page_title_array = "" | split: "" %}

Then loop in your pages :

{% for page in site.pages %}
  {% assign page_title_array | push: page.title %}
{% endfor %}
0
votes

Yeeeeeah...I tried the other two answers here because I had the same issue. However, I stepped back, thought about it, and came up with this!

{% for page in site.pages %}
  {{ page.title }}
{% endfor %}

Wonderful for auto-navigation!