Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Z Template ➋ is a lightweight, dependency-free JavaScript templating library that transforms JSON data into dynamic HTML UI using z-var attributes.
Z Template ➋ is a lightweight, dependency-free JavaScript templating library that converts JSON data directly into dynamic HTML UI using HTML5-compliant z-var attributes and <template> tags.
Z Template ➋ is an open-source (MIT-licensed) JavaScript templating library that transforms JSON data into structured HTML. It takes a target DOM element and a JSON object as input, reads template instructions from z-var attributes and <template> tags, and outputs updated HTML. It runs entirely in the browser, requires only a single JS file and a small CSS file, and has no framework dependencies. The library has been developed and battle-tested for over 6 years on real-world sites.
z-var, template) so templates stay browser-previewable and XSS-free compared to string-based engines.zTemplate() call.zTemplate(element, newData) updates changed values instantly; list rendering compares old and new arrays and only updates changed items.template blocks iterate over arrays or objects; items with an id property are tracked by that id for efficient DOM reuse.foo == 'bar') evaluates true.z-scope and z-scope-children attributes isolate parts of a template from being applied by ancestor calls.--z-anim-speed CSS variable or z-no-anim class; custom animations target template-clone and z-content-rev attributes.template="[items]" to iterate arrays and objects and render nested structures (like a category with sub-items) with smart updates.checked and disabled based on JSON values.Include template.css and template.bundle.min.js (or import the module template.bundle.module.min.js), add z-var instructions to your HTML, then call zTemplate(element, data). The library processes the element's subtree, applies values from the data object to each instruction, and re-runs the same process any time you call it again with new data. jQuery users can also call jQuery.template(...) if jQuery is loaded.
remove action permanently deletes elements from the DOM and cannot be re-applied; the custom z-var syntax and learning curve differ from framework-based templating.Z Template ➋ is free and open-source under the MIT license — no paid tiers or hidden fees.
Other templating libraries include Handlebars, Mustache, EJS, Nunjucks, and JsRender. These typically treat templates as plain strings, whereas Z Template ➋ manipulates the browser DOM directly, which the README highlights as a security advantage against XSS.
Yes, Z Template ➋ is open-sourced under the MIT license, so it is free to use in personal and commercial projects.
No. Z Template ➋ is dependency-free and works standalone with plain JavaScript. If jQuery is already loaded, it adds a jQuery.template() convenience method, but it is not required.
Call the zTemplate() function again on the same target element with the new data object. The library re-evaluates all z-var instructions and changes only what has changed, including smart list updates that reuse unchanged DOM nodes.
toggle and remove actions?The toggle action adds or removes CSS classes to show or hide an element while keeping it in the DOM. The remove action permanently deletes the element from the DOM, so templates cannot be re-applied to it afterwards; the README recommends using toggle in most cases.
Yes, new list items get a slide-in animation by default, controlled by the --z-anim-speed CSS variable or the z-no-anim class. You can customize animations by targeting *[template-clone] for new items, *[z-removed] for removals, and *[z-content-rev] for changed content.