Adding short comments on Jekyll frontmatter date output

40 views Asked by At

I'm learning Jekyll by customizing a theme I bought, and I made the date to display in a way I want by editing this tag and leaving only %B and %Y (that's probably not the way this is called, I'm still learning)

{% if page.date %}
<div class="project-date">
<strong>Date </strong><span>{{ page.date | date: "%B %Y"}}</span>
</div>
{% endif %}

Now on every page that has a Date: field on the frontmatter, I put whatever date is needed there, 2022-01-01 outputs to January 2022 as I want.

But what I also would like is to leave a short remark on each of these entries, separately. So on a Page 1 and its custom date, I'd like to have it display January 2022 - for 2 months and on Page 2 where the date is March 2023, I'd like to add "for 1 month" comment.

How do I achieve this?

1

There are 1 answers

0
maikhel On

If I understand your problem correctly, you want to display additional data based on certain pages configuration. You can achieve it in a similar way as displaying dates, so add to the layout file:

{% if page.months_ago %}
  <strong> For {{ page.months_ago }} </strong>
{% endif %}

and then in Page 1 have a configuration option at the top of the file:

---
months_ago: "1 month"
---

<!-- the rest of your html -->

And accordingly for other pages.

However, if you need to generate months_ago dynamically, you can just use liquid filters in layout file, eg. minus method