{{ site.news }} renders stray `<!DOCTYPE html>`

Hello,

I am building a site using this template. You can see my version of the source files at my fork of this repository.

I am trying to build a news page similar to the projects page in the template, except that the news page should chronologically display each “news” item. Each such item will be a markdown file in the _news folder, so this should be pretty straightforward: I created a “news” page inside the _pages folder, with the following content:

---
layout: page
title: news
permalink: /news/
nav: true
---

Hello, world

  {% assign sorted_news = site.news | sort:"date" | reverse %}
  {% for news in sorted_news %}
    {{ news }}
  {% endfor %}

However, when this renders, there is stray text " <!DOCTYPE html> " next to each news item. I tried replacing news with news.content, but this did not work either: the text does not properly render; instead, I get the output <p> news text .... news text </p>.

Either way would work fine for me! I think the ‘heading’ of each news item is unnecessary on the ‘news’ page, so a nice rendering of just the dates and content (without the title) would also be fine. I primarily intend for each “news” entry to be a small one – planning to migrate my site, including the “events” page, from this one.

I found a fix! Just enclose the {{ news.content }} inside a <article> ... </article>:

  {% assign sorted_news = site.news | sort:"date" | reverse %}
  {% for news in sorted_news %}
  <article class="post-content">
    {{ news.content }}
  </article>
  {% endfor %}
1 Like