Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pure HTML + JavaScript client side templating

I want to have achieve something similar to Java Tiles framework using only client side technologies (no server side includes).

I would like to have one page, eg layout.html which will contain layout definition. Content placeholder in that page would be empty #content div tag.

I would like to have different content injected on that page based on url. Something like layout.html?content=main or layout.html?content=edit will display page with content replaced with main.html or edit.html.

The goal is to avoid duplicating code, even for layout, and to compose pages without server-side templating.

What approach would you suggest?

EDIT: I don't need a full templating library, just a way to compose a pages, similar for what tiles do.

like image 353
Marko Avatar asked Nov 01 '10 21:11

Marko


People also ask

Is JavaScript a templating language?

JavaScript templating refers to the client side data binding method implemented with the JavaScript language. This approach became popular thanks to JavaScript's increased use, its increase in client processing capabilities, and the trend to outsource computations to the client's web browser.

What is HTML templating language?

The purpose of HTML Template Language (HTL), supported by Adobe Experience Manager (AEM), is to offer a highly productive enterprise-level web framework that increases security, and allows HTML developers without Java knowledge to better participate in AEM projects.


3 Answers

JavaScriptMVC has a view templating system that supports different engines, including a pure JavaScript based one called EJS.

You might also want to look into Mustache especially Mustache for JavaScript.

like image 63
Daff Avatar answered Nov 05 '22 08:11

Daff


If you would like to use jQuery, there is a decent templating engine in development as well:

http://github.com/jquery/jquery-tmpl

http://api.jquery.com/jquery.tmpl/

like image 27
Colin Sullivan Avatar answered Nov 05 '22 10:11

Colin Sullivan


Check this out:

http://layout.jquery-dev.net/

I thinks it's close to what you want.

I am looking at javascriptMVC at the same time.

In the forum they are talking about using jquery layout with it.

like image 26
unludo Avatar answered Nov 05 '22 09:11

unludo