Including a link tag in the front matter

Edit this page on Github

For this Stackoverflow question, I could add ansnwer because I have found this blog post some time ago. The question was how to add a link inside a variable in the front matter.

1. Create a filter plugin

1
2
3
4
5
6
7
8
9
10
11
# file: _plugins/expand_nested_variable_filter.rb

module Jekyll
  module ExpandNestedVariableFilter
    def flatify(input)
      Liquid::Template.parse(input).render(@context)
    end
  end
end

Liquid::Template.register_filter(Jekyll::ExpandNestedVariableFilter)

2. Apply the filter

1
2
3
4
5
6
7
8
9
10
11
---
layout: post
title:  "Title"
date:   2022-12-06 18:26:05 +0100
categories: category
author: Author name
author-pic: author.jpg
banner-bottom: [Link to this post]({% link 2022-12-12-flatify-link-from-a-Jekyll-link-tag-in-frontmatter.md %}) using a Jekyll link tag in the page's front matter.
---

{{ site.baseurl | flatify }}

The result

The link tag in the front matter displayed above is properly converted into a link in the content:

This is a Link to this post using a Jekyll link tag in the page’s front matter.

Send feedback!

<b>Written by:</b> Christian
Written by: Christian Technical writer, nerd, father.