0
votes

Short Version:

Why does the following code not produce an output when navbox.next_article is the string '2018-01-05-man-command'?!

{% capture np %} {{ site.posts | where:"post","navbox.next_article contains post.title" }} {% endcapture %}
The next post is {{ np.title }}

Details

My post 2018-01-05-man-command.md has a YAML front matter:

---
layout : post
title : 'Man Command'
tags : [RHCSA, RHCSA_mod, Using Essential Tools, Man Command]
categories: [RHCSA]
navbox:
#  prev_article:
  next_article: 2018-01-05-understanding-globbing-and-wildcards
---

This is accessed by the _includes/post.html file through:

{% unless include.excerpt %}
  {{ post.content }}
  {% include navbox.html navbox=page.navbox %}    
{% endunless %}

This is used by the _layout/post.html which sets the layout for the post:

{% include post.html post=page link_title=false %}

My navbox.html contains:

{% assign navbox = include.navbox %}

{% capture np %} {{ site.posts | where:"post","navbox.next_article contains post.title" }} {% endcapture %}
The next post is {{ np.title }}

However, all I get when I run bundle exec jekyll serve is:

The next post is

Why does that line not work? I'm new to jekyll so it's possible I've made a blunder somewhere that's intuitive to most. Please tell me what I can fix.

1

1 Answers

1
votes

I believe that the capture tag only captures strings, not posts. See here for more info.

I'm not convinced that a where filter supports the contains syntax you're using. See here for more info.

On top of that, where returns an array. You have to get the first item from that array.

You need to fix these issues. Use an assign instead of a capture to store a post. And change your where filter to not use the contains syntax, which isn't valid. (Unless it's been added since the issue I just linked.)

Here is how I've done it:

{% assign post = site.posts | where:"url", targetUrl | first %}