Often, when you're building a prototype or a simple (maybe static) website, you'll find yourself making a bunch of static HTML pages that you link together. And most of the time, there are things that are the same on every single page. The header. The footer. An email signup form. Etc.
There are many different ways of avoiding the bother of having to copy and paste this common content between pages (not to mention what a pain it is to edit every single page whenever you need to change something).
When I was looking for a solution to this problem, I found that most of these ways are quite complicated. There are static site generators like Jekyll, Pelican, and Octopress. (And many, many others.) There are the templating languages, such as Handlebars, Mustache, and Jinja2. And there are powerful but complex frameworks like AngularJS that come with this of functionality built in.
I've looked at all of these at various times and for various reasons, and I was left gibbering – they were all complete overkill for what I was trying to do. Their learning curves just weren't worth it.
And then I found Brace Tags. All it does is pull pieces of content into HTML pages. That's it. Nothing more.
Let me show you.
Let's say you've got a web page that looks like this:
<html>
<head>
<title>My homepage</title>
</head>
<body>
<h1>Welcome to my homepage</h1>
<p>Look at all this content!</p>
</body>
</html>
And you want to add a footer to this page (and to all your other pages). You create a folder called _partials
in the same folder as your HTML files and create a file containing your footer markup in it. Call it, say, footer.html
. Something like this:
<footer>
<p>Copyright © Martin Polley 2016</p>
</footer>
Then add one line to the first file to pull in the footer, so it looks like this:
<html>
<head>
<title>My homepage</title>
</head>
<body>
<h1>Welcome to my homepage</h1>
<p>Look at all this content!</p>
{% include _partials/footer.html %}
</body>
</html>
Then you run Brace Tags on it by typing tags build
at the command line in the folder containing your files. It assembles the pages and puts them in a folder called _site
. That's it. Dead simple, with a minimum of faffing about.
The thing is, it only runs on OS X or Linux. But I'm on Windows at the moment, so I've set up a virtual machine running Linux just so I can run Brace Tags. It's worth the hassle of setting up a VM to have access to such a simple, useful tool.
If you found this useful, and don't want to miss out on more like it, sign up for my (rather irregular) newsletter.