I have an directory called /patterns in my Jekyll site, whose structure generally looks generally like this:
_includes
_layouts
_site
/patterns
index.html
I need to keep the /patterns directory outside _includes for a number of reasons, but mostly because I need to pull the files in /patterns into an iframe to display in a pattern library).
I'd like to include files from /patterns in my Jekyll pages, but using {% include /patterns/file.html %} doesn't work as it points to the_includesfolder. How would I go about including a file from a directory that isn't_includes`?
You can change the directory that the include tag uses with includes_dir in your _config.yml. It doesn't look like you can set multiple paths (source: https://jekyllrb.com/docs/configuration/).
In any case, the files in _includes don't end up in your output. You could separate pattern-specific includes into _includes/patterns/, but the only thing that'd have any effect on your live site would be where those files were included.
You can choose to include file fragments relative to the current
file by using the include_relative tag for your
/patterns/file.html

For the directory structure you have:
_includes
_layouts
_site
/patterns/file.html
index.html
In this case the following doesn't work:
{% include /patterns/file.html %}
Use include_relative as /pattern is relatif to index.html as the current file:
{% include_relative patterns/file.html %}
Note:
You can't use the include_relative tag with any files inside your layouts folder. You can only use include_relative on a page or post. Layouts code is executed in the context of page/post rendering and the include_relative is calculated relative to this page or post, not from the layout itself.
In this case your code on index.html shall be:
---
layout: null
---
(put all code from _layouts/default.html)
{% include_relative patterns/file.html %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With