0

I have a large website with several consistent text, like the nav, contact, footer, etc. I was wondering how I could keep all of these consistent on my static website (hosted on github pages) by loading the code from another file or any other method, since currently I have to manually update everything and it takes a while.

0

1 Answer 1

1

Github pages uses Jekyll as the underlying static site generator. You can break down your site into multiple smaller html pages that can be included into a main layout.

https://jekyllrb.com/docs/includes/

The include tag allows you to include the content from another file stored in the _includes folder:

{% include footer.html %}

Jekyll will look for the referenced file (in this case, footer.html) in the _includes directory at the root of your source directory and insert its contents.

Read the documentation on this and you can easily find repeated text/html and replace them with includes.

If you're not already, this site has instructions so you can run jekyll locally to verify changes before pushing the changes to Github.

Sign up to request clarification or add additional context in comments.

2 Comments

If I add css classes to it, would those be able to work from the style.css called from the html file it was generated into?
@theAnshulGupta Read the documentation on SASS: jekyllrb.com/docs/structure

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.