Stefan Baumgartner

Web ops, performance and front-end

Custom Jekyll Includes Directory

01 September 2015 by @ddprrt | Posted in: 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 %}

Comments? Shoot me a tweet!