Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Offline HTML templating

I'm designing a simple website with no dynamic content that I want to be light and 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?

like image 282
s4y Avatar asked Feb 04 '10 23:02

s4y


People also ask

How do you do templating in HTML?

The <template> tag is used as a container to hold some HTML content hidden from the user when the page loads. The content inside <template> can be rendered later with a JavaScript. You can use the <template> tag if you have some HTML code you want to use over and over again, but not until you ask for it.

Can I download a website for a template?

There are many sites that offer web templates free downloads. Some of them are affiliated with website builders or hosting services while others are individual designers specializing in different website building services that allow the use of third-party HTML web templates on their platforms.

What is templated HTML?

The <template> HTML element is a mechanism for holding HTML that is not to be rendered immediately when a page is loaded but may be instantiated subsequently during runtime using JavaScript. Think of a template as a content fragment that is being stored for subsequent use in the document.

Can I use free templates for my website?

A majority of web hosts and website builders offer their clients free templates they can use to create their websites quickly. Many will discover that free templates can provide everything they need to succeed, provided they are willing to tolerate the drawbacks of using them.


3 Answers

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'
%]
like image 75
Quentin Avatar answered Oct 15 '22 03:10

Quentin


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

like image 37
scunliffe Avatar answered Oct 15 '22 03:10

scunliffe


Webby is fantastic for exactly this.

Another great option is Jekyll.

like image 44
user342492 Avatar answered Oct 15 '22 01:10

user342492