2

I'm using staticman to enable comments on my blog. It puts the comments in the _data folder. My folder structure then looks like this:

_data/
    comments/
        blog-post-1/
            entry1542891129928.yml
            ...
        blog-post-2/
            entry1542891129928.yml
            ...
        ...

In my _layouts/post.html I want to access comments for a specific blog. This is the code that I expect to work to get to the comments:

{% assign comments = site.data.comments[page.slug] | sort %}

But when I run build, I get the following error:

Liquid Exception: Liquid error (line 39): Cannot sort a null object. in /_layouts/post.html

It seems to be something to do with page.slug because if I replace it with the string 'blog-post-1' it works.

How to get the post slug dynamically in post.html?

1 Answer 1

4

Solved the problem!

The issue is when the folder does not exist. I circumvent this by moving the sort filter:

{% assign comments = site.data.comments[page.slug] %}
{% if comments %}
    {% assign comments = comments | sort %}
    ...do things...
{% endif %}

Now the build doesn't fail.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.