Search code examples
jekyllliquidyaml-front-matter

Jekyll for loop can't work as expected


I created a new page, there was a for loop to display the list of posts, but it can't work as expcted enter image description here

and here is my code:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<ul>
  {% for post in site.posts %}
    <li>
      <a href="{{ post.url }}">{{ post.title }}</a>
      {{ post.excerpt }}
    </li>
  {% endfor %}
</ul>
</body>
</html>

Solution

  • Add front matter so Jekyll knows it has to process it.

    Simply add two lines of the dashes at the beginning of the file:

    ---
    ---
    <!DOCTYPE html> 
    <html> 
    <head> <title></title> </head> 
    <body> 
    <ul> 
    {% for post in site.posts %} 
    <li> <a href="{{ post.url }}">{{ post.title }}</a> {{ post.excerpt }} </li>
     {% endfor %} 
    </ul> 
    </body>
     </html>