Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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.

share|improve this question

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.

share|improve this answer
    
Ah, good ol' m4. Hadn't thought of that :-) I also realized I could user server-side includes (.shtml) –  raindog308 Mar 6 '13 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.

http://www.smarty.net/

share|improve this answer

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.

share|improve this answer

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:

http://www.tizag.com/phpT/include.php

share|improve this answer

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:
http://httpd.apache.org/docs/2.2/howto/ssi.html

share|improve this answer

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

share|improve this answer
    
And here is Static Site Starter Kit powered by assemble.io, Gulp, Handlebards, Bootstrap, LESS: github.com/kriasoft/static-site-starter –  Konstantin Tarkus Jul 12 at 19:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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