No commit activity in last 3 years
No release in over 3 years
The built in include tags don't handle files that have frontmatter. This will, and if the frontmatter is a hash, it will be used to populate params for the include.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.17
~> 5.0
~> 10.0

Runtime

>= 0
 Project Readme

JekyllIncludeWithFrontmatterTag

Jekyll's include and include_relative tags are straight includes -- they don't deal with files that have frontmatter.

When working with a Jekyll site that uses Netlify CMS, though, one may want to be able to edit the includes via Netlify CMS. Netlify writes Markdown with frontmatter, though. The solution is to create a couple new tags, includefm and includefm_relative, which inherit from the Jekyll include tags, and add handling of frontmatter.

Frontmatter gets treated as params passed into the include. If there is an include param with the same key as a frontmatter param, the include param takes precedence. Thus, frontmatter params can be thought of as defaults param values for the include.

In all other ways, includefm and includefm_relative should work the same as include and include_relative.

Installation

Add this line to your application's Gemfile:

gem 'jekyll-include-with-frontmatter'

Also add a corresponding line to your Jekyll config.yml:

plugins:
  - jekyll-include-with-frontmatter

Usage

Files which are to be included can include frontmatter:

---
title: Documents
---
<div id="documents-column">
  <div class="bg-blue">{{ include.title }}</div>
  <div class="bg-grey"><a href="/media/pdfs/doc1.pdf" target="_blank">Document 1</a></div>
  <div class="bg-grey"><a href="/media/pdfs/doc2.pdf" target="_blank">Document 2</a></div>
  <div class="bg-grey"><a href="/media/pdfs/doc3.pdf" target="_blank">Document 3</a></div>
</div>

In your post, page, or layout, you include with frontmatter like this:

{% includefm documents.html %}

These tags should work just like the standard Jekyll include tags on files that do not include frontmatter, as well.

TODO

There are, effectively, no tests. Tests are needed.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/wyhaines/jekyll-include-with-frontmatter.

License

The gem is available as open source under the terms of the MIT License.