How does the loops and variables in Jekyll work?

Asked

Viewed 73 times

-1

When I compare in if if the post.category it’s like there’s no post variable that’s in for more when I put {{post.category}} it prints the name. It’s like in if he wouldn’t exist anymore if I put site.post.category no if takes all values.

The problem is that I want to take the current post to compare if it’s that category. I want to list posts by category.

<div class="posts">
  {% for post in site.posts %} 
    {% if post.category == Eventos %}
      <hr />
      <div class="post">
        <h1 class="post-title">
          <a href="{{ site.url }}{{post.url}}">
            {{ post.title }} 
          </a>
        </h1>
        <span class="post-date">{{ post.date | date_to_string }} / {{ post.category }}</span>
        {{ post.excerpt }}
        <h6><a href="{{ site.url }}{{post.url}}">Leia mais...</a></h6>
      </div>
    {% endif %}
  {% endfor %}
</div>

1 answer

1


The loop syntax is correct, adjust the if for:

{% if post.category == "Eventos" %}
  • How simple, thank you very much @luciorubeens

  • If the answer was accepted as correct, mark as "best answer", please.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.