I have a site that is 100% static content (no php, just some javascript). There's several "blocks" like the header, menu, footer, etc. that are the same on each page.

Rather than do a lot of copy/pasting, I was thinking of some kind of template system where I could run a CLI command (in php, perl, python, shell, whatever) and have it replace all the block tags with the actual block text.

I did see some answers in this question, but those seem oriented towards "we provide the style and layout, you provide the text". In my case, I have everything as far as layout, css, etc. - just want to do a glorified sed.

Before I invent the wheel, I was wondering if there was a tool out there already.

6 Answers 6


I wrote my own system for doing this called Better Templates for Everybody. I open sourced it and make it freely available. It works well enough for me, but it has never received widespread adoption.

I've also seen M4 Macros used for this purpose.

You could also consider powering your pages PHP and using #include directives.

  • Ah, good ol' m4. Hadn't thought of that :-) I also realized I could user server-side includes (.shtml)
    – raindog308
    Mar 6, 2013 at 17:55

Ultimately I used Smarty. Setup your template vars, fetch(), and echo. A little logic to iterate over input files and write the output to the output dir and things are working. The iteration, input/output, etc. were easier to write than to invent a new template language and this way I have all of Smarty's many features at my disposal.



There are tools for that and considering your site is mostly static, you should go for the simpler ones, otherwise you'll get more complexity without using its benefits.

Adobe Dreamweaver has a mostly WYSIWYG editor that does exactly that. You start with a styled template and you work to fill it as many times as you like. It will highlight and autocomplete for you and prevent you from damaging template areas.


Have you tried php 'include'?

you can make a "header.php" file with all the info about the header, or just even a "menu.php" and then just make a call from the index.php

So for every other page you make you don't have to copy all your html again, just 'include' via php, this is specially handy when you are testing such included blocks and you are modifying them all the time, if you just plain html you have to modify every single one.

Check this tutorial:



I run apache2 for my web server, and it has a feature where you place <!--#include virtual="/cgi-bin/counter.pl" --> in the html code and it will send the code of /cgi-bin/counter.pl in the place of that tag.

For more info:


Try http://assemble.io, it's 100% javascript and runs on Grunt.js.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.