Search code examples
javascripthtmltemplatesclient-sidetiles

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.


Solution

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