I am building a static-website (as in, to change a page, we change the HTML and there is no DB or anything). Well, it will have a number of pages and I don't want to copy and paste the HTML navigation and layout code around everywhere.
So what would be the best platform to use in this situation so I can have all my layout and "common" HTML markup all in one place?
You can just use HTML and add server side include [1] files. Most servers support this, and both Apache and IIS are capable.
I just use ASP.NET MVC because I love it, but PHP would also work depending on your desired platform.
[1] http://en.wikipedia.org/wiki/Server_Side_IncludesI'll throw down a vote for PHP just because of its simplicity for small requirements like this. If you are hosting on a cloud or a managed environment then they most likely will have the required php backend setup and all you need to do is:
change the extensions of all your pages from .html
to .php
create template files named
something like header.php
and put
them in an /includes/
directory.
Inside these 'template' files can be your html for
various re-used sections of your
site.
<?php
include_once 'includes/header.php'
?>
Easy-peezie lemon-squeezie.
If you want something more complex and structured, one of these other answers is more appropriate.
Josh
I've been using Template Toolkit [1] for this, specifically the ttree utility [2].
There are no server dependencies (because all the combining of files happens at build time, not run time) and that makes is trivial to configure the server for good cache control and compression options.
[1] http://template-toolkit.org/Well, there are a few ways to do it:
include()
/require()
functions to include the headers. Might be a tiny little bit less efficient, but you won't really be able to feel it, and if you decide to make it more dynamic in the future, it'll be easier to upgrade.<head>
, it's also the cleanest.Jekyll [1] is a newish static site generator written in Ruby. It's popular among the Ruby/GitHub–type crowd, and at least one person I know uses it for his own websites. It seems pretty nice.
You could also look at Hyde [2] (I kid you not), which is essentially the same thing but in Python with Django, so you can use Django features to generate your content.
[1] http://jekyllrb.com/I was in a similar position to you. I tried all sorts of static site generators. I settled on Middleman [1]. It's easy to use, and I like that it is very similar in layout design to Ruby on Rails.
[1] http://middlemanapp.comI choose django for this kind of work. Its features like:
Besides those features that IMO fits in your requirement, django is also unobstrusive and very lean. It's fairly easy to get started, especially if your requirement is only for static pages.
But this is if you have the luxury to have Python as your platform. Otherwise as others have suggested, PHP might be a better fit.
[1] https://docs.djangoproject.com/en/1.4/ref/generic-views/#django-views-generic-simple-direct-to-templateIf it;s just a bunch of static pages you dont need ASP.net or PHP , just plain HTML is good enough !
You may want to look at TiddlyWiki [1], a CMS contained in a single html file.
[1] http://tiddlywiki.org/wiki/TiddlyWiki