1

I have built a website (using GitHub pages) which contains a lot of sub-pages. Almost each one of these pages contains the following same content, e.g. footer part like this:

<footer id="content-info" class="container" role="contentinfo">
    ...
</footer>

My question is: how to extract this shared same part out to a separate file for reusing? Then I can simply somehow include this file wherever I need to contain the footer part. If this is possible, I can easily edit this part once and all pages that contain it will change automatically.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
herohuyongtao
  • 49,413
  • 29
  • 133
  • 174

3 Answers3

4

GitHub Pages supports Jekyll, a static site generator. Jekyll uses Liquid templating under the hood. You should be able to leverage the templating even without the static site generation.

Here is more info on Jekyll: http://jekyllrb.com/docs/home/

To get Jekyll to process with GitHub Pages, you probably need to add a _config.yml file. More info on that here: http://jekyllrb.com/docs/configuration/

Then once Jekyll is processing your .html files, you can use a simple templating syntax to include content form other files.

Example:

<!-- html here -->
{% include footer.html %}
<!-- more html here -->

This will include the contents of _includes/footer.html by default. More info on template includes here: http://jekyllrb.com/docs/templates/#includes

I hope that helps!

herohuyongtao
  • 49,413
  • 29
  • 133
  • 174
Will Klein
  • 2,244
  • 17
  • 18
-1

Your pretty much right on the money, take the code snippets you want to reuse and save them as seperate files.

Then use

<?php include_once ("file location/filename.extension"); ?> 

to include that file :D

##### html file
<html>
<head>
<title>Title</title>
</head>

<body>
<p>content here</p>
<?php include_once ("file location/filename.extension"); ?>
</body>
</html>
##### include file
<p>copyright by me<p>
lil_bugga
  • 81
  • 2
  • 14
  • Thanks. But it doesn't work for me. Is it related to GitHub pages that I use to built my website? Maybe it doesn't support PHP? – herohuyongtao Jul 15 '14 at 13:00
  • Have you got the main pages saved as html or php. It could just be a matter of the wrong file format. Unless specified with a .php extension I don't think it will work. – lil_bugga Jul 15 '14 at 13:01
  • 2
    Pages are saved as HTML. GitHub doesn't support PHP, as discussed [here](http://stackoverflow.com/a/10837990/2589776). Sad news :( Any idea to work around? – herohuyongtao Jul 15 '14 at 13:04
  • 1
    Sounds like you don't have that many options left open to you. I suggest looking at frames. I used to build sites with frames and each frame effectively had a separate page controling it. Frames I think have been superseded by IFrames so might be worth having a look at them. – lil_bugga Jul 15 '14 at 13:21
  • Thanks. I will check on that. – herohuyongtao Jul 15 '14 at 13:27
  • Did you have any sucess with the frames or Iframes? – lil_bugga Jul 17 '14 at 12:34
-1

You could simply copy the content of the div to a php or html file and call it from each page using

<?php include 'footer.php'; ?>

That way when you change footer.php it'll update across the site.

GazEcc
  • 5
  • 6
  • 1
    As discussed [here](http://stackoverflow.com/a/10837990/2589776), GitHub doesn't support PHP. Any idea to work around? – herohuyongtao Jul 15 '14 at 13:13