3

I have a file called default.html in my layouts folder. In default.html, I want to add a relative include to test.html, which is also in my layouts folder.

I add {% include_relative test.html }% in my default.html file to include test.html. However, when I do this, I get an error that says

"Liquid Exception: Included file './test.html' not found in
projects/[projectnmae]/layouts/default.html"

I do have my layouts folder in a different location, as specified in my configuration file. Any ideas if include_relative works in a special way here that I'm not grasping?

Mike Lyons
  • 1,748
  • 2
  • 20
  • 33
Tom Johnson
  • 729
  • 8
  • 17
  • Check the file name. Maybe it's certainly **tests.html** – David Jacquel Feb 19 '15 at 22:07
  • No, I don't have a typo in the filename. I think this is a bug with Jekyll. – Tom Johnson Feb 20 '15 at 18:43
  • This can then be very interesting to see you code. Any github repo ? – David Jacquel Feb 20 '15 at 19:25
  • Sure. Here's the repo: [https://github.com/tomjohnson1492/jekyll-doc](https://github.com/tomjohnson1492/jekyll-doc). – Tom Johnson Feb 20 '15 at 22:42
  • I don't think it's a theme issue, though. I replicated the issue using a new jekyll site. In this github repo, I'm trying to put everything related to one site into a specific project folder. The _includes folder is the only thing I couldn't move there. – Tom Johnson Feb 20 '15 at 22:45
  • Well, if you reproduce this bug on a new jekyll site, it will be easier to spot it. Can you push the code on a github for examination ? – David Jacquel Feb 20 '15 at 23:37
  • The project is extremely simple. There are just a few steps to reproduce the bug. I uploaded it as a zip file here: http://idratherbewriting.com/test123.zip. Just run `jekyll serve` and you'll see the error. Edit default.html to remove test.html and the error goes away. – Tom Johnson Feb 22 '15 at 00:17

2 Answers2

8

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.

Tom Johnson
  • 729
  • 8
  • 17
5

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.

Tracking this error in debugger shows that include_relative tries to load /home/user/www/test/_posts/test.html and not /home/user/www/test/_layouts/test.html

David Jacquel
  • 51,670
  • 6
  • 121
  • 147