views:

257

answers:

7

Hello, 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?

+6  A: 

You can just use HTML and add server side include 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.

Dustin Laine
Our platform is not completely decided. I personally like PHP. I know ASP.Net Webforms, but not MVC. I feel like MVC would be overkill for this, and we will be doing some javascript things, which is where Webforms starts to really suck.
Earlz
just make sure to check with your hosting provider...
Paulo Santos
Right now our hosting supports all 3, so it's not a problem..
Earlz
MVC is simple and provides nice features and clean markup.
Dustin Laine
+1 for good ol' SSIs.
maerics
+2  A: 

I've been using Template Toolkit for this, specifically the ttree utility.

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.

David Dorward
+2  A: 

Well, there are a few ways to do it:

  1. Simply use frames. It's an old and somewhat clunky technique, but it is probably the fastest for the server side.
  2. Use server side includes. Very efficient but somewhat ugly and you won't be able to upgrade it if you ever decide to add more flexibility.
  3. Use a scripting language like PHP and its native 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.
  4. Have a single main handler page with all the persistent navigation and whatnot, then include your content pages, while doing an internal URL rewrite behind the scenes. This is probably the least efficient of the four, but the margin is too low to notice, and unless you need your content pages to add something into the <head>, it's also the cleanest.
Max Shawabkeh
ewww.... frames
Earlz
"unless you need your content pages to add something into the <head>"? Like a title?!
David Dorward
@Earlz: They're there for the sake of completeness.@David: I was more referring to something like arbitrary code, scripts/styles/meta tags, where it'd get unnecessary complex without a db. Preset stuff like titles can be easily arranged though.
Max Shawabkeh
A: 

I choose django for this kind of work. Its features like:

  • direct_to_template is useful to render the template directly and if I want to have full-control with the template
  • or flatpages, is useful if I want to administer the content of the static page, like a CMS, from its built-in admin system

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.

jpartogi
A: 

Jekyll 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 (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.

Paul Fisher
I lol'd at the Jekyll and Hyde bit..
Earlz
+2  A: 

I'll throw down a vote for PHP just because of it's 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:

  1. change the extensions of all your pages from .html to .php

  2. 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.

  3. call these files with <?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

Josh Pinter
I accepted your answer because it's the most specific for what I'm doing.. but I also built a middle step so that I can "build" all the PHP pages into HTML and then just deploy the HTML
Earlz
I've never done it like that before but if it truly is static than html would be best for the end product. Another small bonus of using php is that you can easily generate simple dynamical content such as updating the copyright year: Copyright Earlz (c) 2009 - <?php echo date('Y') ?>But it sounds like you know what you're doing :)
Josh Pinter
A: 

You may want to look at TiddlyWiki, a CMS contained in a single html file.

Marcel
I love tiddly, but it doesn't belong on the web as an actual website IMO. Plus, very hard to really customize..
Earlz