Can you use subdirectories within Jekyll's _in

2019-05-07 01:41发布

问题:

My plan is to have folders within the _includes directory:

_includes/footers

_includes/heros

_includes/cta

etc...

When I reference that {% include footers/footer1.html %} I get the following error:

Liquid Exception: Included file '_includes/footers/footer1.html' not found in _layouts/default.html

Is this outside the intended functionality, or am I missing something?

回答1:

Yes you can nest partials. Subdirectories don't have to be prepended with an underscore.

Let's say you have a footers folder inside the _includes folder.

_includes/footers

You could include your resources by adding the relative path:

{% include footers/footer1.html %}


回答2:

This is one of those scenarios where I came back to it, seemingly tried the exact same thing, and it worked.


  • You can use subdirectories within _layout folders
  • You don't have to use underscores for it to work (Perhaps this is just a best, practice?)


回答3:

On jekyll 3.0.1 you don't have to use _ to prepend directories in _includes. I have a structure like _includes/foo/file.html, _includes/bar/file.html and I use it like {% include foo/file.html %} and {% include bar/file.html %}. It works perfectly fine without underscores. This might be a behavior that is not present in other versions of Jekyll.