Search code examples
javascripthtmlhandlebars.jstemplate-enginemustache

Include html files in an html file on a local file system?


I have a help system that is completely offline, no server, using file://.

I have one main page, with hundreds of line of html that represent many sections of the help system. I would like to stick each section in a html file and just include it. Unfortunately it seems like this is only possible with some nifty server side include techniques, with HTML5 (which I do not want to assume my users have), or with a nasty javascript hack where you copy your html file into js files with document.write calls for every line as written about here: Ways to include html in html.

What about something like handlebars.js or mustache.js? Can I use templating?


Solution

  • Since you don't want to use server-side includes, I would suggest using a static site generator (SSG).

    If you are not familiar with SSG's, they allow you generate HTML pages from templates & includes (often Handlebars templates) and HTML, Markdown, JSON, or YAML, content using a CLI.

    If you want to get started with an SSG, there are plenty of options, from Ruby based Jekyll, or Node.js based Assemble. In my opinion, Assemble is the best option and I would highly recommend it.