1

I created a website which has same header and footer in every page. Now if I want to change anything in header or footer, I'd to change all the html files.

Is there any simple solution to avoid such repetitive work? I'm looking for something which works like {{ % include header.html % }} in jekyll.

Sandy
  • 161
  • 5

2 Answers2

2

From your question it seems like you are missing/not fully understanding the concept of templates. A template contains the include of the header.html and footer.html. The page only contains a reference to the template. This is the way Jekyll prevents the repetitive work of adding the include to every page.

Ideally the page is a (index).md file with frontmatter like this:

---
title: Title of the page
layout: template
---
Lorem ipsum

The template file is called template.html and resides in the folder _layouts. It looks like this:

{% include header.html %}
{{ content }}
{% include footer.html %}

Hope that helps!

Mr. Hugo
  • 11,887
  • 3
  • 42
  • 60
1

There is such a method:

{% include header.html %}

Upload the header.html to the _includes folder in the root of your website.

Mr. Hugo
  • 11,887
  • 3
  • 42
  • 60
  • 1
    Note that you can also pass parameters to the file being included. See this answer: http://stackoverflow.com/a/37801163/211672 – C. Augusto Proiete Jul 04 '16 at 12:44
  • @JoostS Well, I am aware of that. I'm just wondering if there's any other method. Building sites in jekyll isn't comfortable for me. – Sandy Jul 04 '16 at 19:39
  • @Sandy To avoid repetitive changes to the header and footer you should use the include method, mentioned in the answer. This is the (only) way this works in Jekyll. – Mr. Hugo Jul 04 '16 at 20:20
  • I'm sorry if my question was confusing. What I actually meant was, I don't want to use jekyll or any other static site generators. I like old fashioned way to coding html pages. So, if I create a website with 6 pages, which has same header and footer, it's time consuming if I need change content of header/footer as I've to change all 6 pages. So, I just wanted to know if there's any quick solution for that. – Sandy Jul 05 '16 at 13:58
  • If you want to do this with plain php, use: `` – Mr. Hugo Jul 05 '16 at 14:17