Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create DRY HTML?

I have a small static website and every page of this site has a menu and a footer.

What is the best way to make sure changes in the menu and the footer only need to be done in one place and enable me to easily update all my pages which consist of them.

I am looking for some kind of simple template system that enables me to combine files together.

I have looked a bit into ruby .erb files but they seem too complicated for what I want to achieve as I would have to install rails and enable my webserver to use that.

like image 946
FlyingFoX Avatar asked Oct 08 '11 12:10

FlyingFoX


3 Answers

For a simple site, there's nothing wrong with doing server side includes. Simply create the HTML snippets (they don't even have to be fully formed HTML) for your menu and footer. Then on each page, add the appropriate

<!-- #include virtual="/footer.html" -->

statement in the proper location. Since you're on a Debian server, I'm pretty sure Apache wil already have this enabled by default.

It may seem antiquated, but my wife works for a company that does a lot of maintenance for small websites and they still take this approach and it works just fine.

If your site goes above 10 pages, then I'd say look into some of the templating systems, just to alleviate the need to remember to add your SSI on each new page you create.

like image 86
Dillie-O Avatar answered Nov 07 '22 02:11

Dillie-O


you could have a look at some Web Templating Systems and decide based on the language/platform you are familiar with

like image 3
Tudor Constantin Avatar answered Nov 07 '22 02:11

Tudor Constantin


I use Octopress. It's a static site generator built on top of Jekyll which uses markdown for content markup and specific template language for constructing pages. So if you only need a site with a few pages you should try jekyll.

It requires for your system to have ruby since all site generation is done on client side and afterwards the site is deployed via rsync.

like image 1
Eimantas Avatar answered Nov 07 '22 01:11

Eimantas