HomeArticles

Custom Jekyll Includes Directory

Stefan Baumgartner

Written by @ddprrt

More on Jekyll

If you want to have a custom _includes directory, and maybe more than one _includes directory, you can easily achieve this by adding a new tag to your existing Jekyll tag library:

module Jekyll
module Tags
class SnippetTag < IncludeTag
def resolved_includes_dir(context)
context.registers[:site].in_source_dir('_snippets')
end
end
end
end

Liquid::Template.register_tag('snippet', Jekyll::Tags::SnippetTag)

Put this in a file in your _plugins directory, then use it then with {% snippet test.md %}

More articles on Jekyll

Stay up to date!

3-4 updates per month, no tracking, spam-free, hand-crafted. Our newsletter gives you links, updates on fettblog.eu, conference talks, coding soundtracks, and much more.