开发者

Offline HTML templating

I'm designing a simple website with no dynamic content that I want to be light and开发者_Go百科 portable — no PHP or other server-side scripting needed, or wanted. I'm running into a question that I've had a few times before.

I'd love to be able to write common elements (head, foot, navigation) once and write the individual pages on the site with content only, then run this mysterious utility to compile everything it into a set of HTML files ready for uploading. A page might be written like this:

Title: Our Services
Top Navigation: Yes
Scripts: jquery, lightbox

<p>
    Example, Inc. offers a wide range of…

It'd be great if the engine also had logic that lets me include or exclude elements (like Top Navigation above) from each page, and automate tasks like labelling the current page in the navbar:

<a href="/services"{page == 'services' ? ' class="current"' : ""}>Services</a>

Are there any engines out there like this?


I'd head directly towards Template-Toolkit for this. It comes with the ttree utility for building a static site.

You can handle the last part of your question with something like:

[% 
    INCLUDE 'navbar.tt' 
    page = 'services'
%]


To be honest, this is where things like PHP come in handy... to include common elements

Option 1: Use a language and enjoy it.

Option 2: Use the language to make the site... but then point a crawler at your site to grab the generated "static" content. e.g. WinHTTPTrack


Webby is fantastic for exactly this.

Another great option is Jekyll.


Adobe Dreamweaver's Templates do what you need if a non free tool is fine for you.

Basically you create a Template page where you define which parts are editable, then you create all your pages based on the template. If you change the template and save it all the associated pages are updates.

The templating system also has the ability to define default attributes and change them in a specific page. You can use this for labeling the current page, though for this IMHO a couple of lines of jquery code are much better.


You could write a program in any language you are familiar with that outputs static html files. You could have a basic structure and then for the customized stuff, you include it from a separate file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜