2
votes

I would like to know if it's possible to add if statement in Front Matter to be selective about using attributes depending on page.url

The pages are generated from .md file virtually from a plugin using a base template so I need to add some conditions in Front Matter if possible.

This is a typical Front Matter

---
...
title: blah
description: blah blah

image: some-image.png
---

I want to do the following:

---
...
title: blah
description: blah blah

{% if page.url == "page1" %}

image: page1-image.png

{% else %}

image: general-image.png   

{% endif %}
---
1

1 Answers

4
votes

Jekyll does not parse Liquid in Front Matter out of the box but there are plugins out there that can parse Liquid in Front Matter for you.

That said, I think your use-case can be easily solved within the page's "layout" itself..

{% capture image %}
  {% if page.url == "page1" %}
    page1-image.png
  {% else %}
    general-image.png
  {% endif %}
{% endcapture %}

{{ image | strip }}