Search code examples
htmljekyllgithub-pages

HTML from _includes not showing where included using Jekyll


I'm hosting a personal site using GitHub Pages.

I'd like to reduce HTML code duplication by taking advantage of GitHub's builtin Jekyll templating functionality. For instance, putting footer.html into a /_includes directory for reuse on every future page.

I also happen to enjoy organising my files, so I put my 'real' index.html inside a /html sub-directory, along with all my other html files. GitHub pages doesn't like this, so I have used a dummy index.html in the root directory so that the site will be loaded by GitHub.

Whenever I use:

---
---

at the top of a .html file within my /html directory, they rather strangely get rendered as text at the top. In fact, so do my {% includes foo.html %} calls.

Why is this happening?


Solution

  • If you are using the 'dummy' index.html workaround, you will also need to enable Liquid in the root there by placing:

    ---
    ---
    

    at the top of your dummy index.html:

    index.html (dummy) <- double '---' here
    html/
    ├─ index.html
    ├─ foo.html <- double '---' here to use {% includes bah.html %}
    _includes/
    ├─ bah.html
    

    This question helped the penny drop.