GTPL Documentation Playground

GTPL is a TypeScript library for reactive template systems built around Direct DOM and Proxy. Inspired by Vue, Angular AOT, and JSX, it delivers efficient reactive UI updates in a compact 11kB JavaScript package.

Repository Releases Quick Reference API Summary

Pipeline

template -> GCode -> GCompile -> GTpl

Reactive Core

State changes are observed via Proxy and mapped to bind trees for direct DOM updates.

Directive Model

Use built-ins like g-if, g-for, g-switch or register your own directives.

Basics: variables and constants

Functions, formulas, and events

Bidirectional variables

Attributes

.cls { color: #00f; } 
.weight { font-weight: bold } 
div[custom='value'] { background-color: #ff0; }

Styles

Conditional rendering

Switch

For

Templates

Inner HTML

Quick Reference

Template expressions are wrapped in {{ ... }}. GTPL supports variables, constants, chained functions and formulas.

  • {{ foo }}: read variable
  • {{ 'constant' }}: constant value
  • {{ foo:format }}: pass through function
  • {{ return foo + 1 }}: formula expression
  • [value]="{{ foo }}": two-way bind attribute/property
  • g-if, g-notif, g-switch, g-case, g-for, g-inner

API Summary

API Purpose Example
gtpl.jit.GCode(html) Transform template HTML into AOT code string. const aot = GCode(template)
gtpl.jit.GCompile(aot) Compile generated AOT string into element generator function. const gen = GCompile(aot)
new gtpl.GTpl(options) Create reactive instance bound to a root object. new GTpl({ root, generator: gen })
instance.addTo(node) Append rendered template to target node. instance.addTo(container)
instance.watch(path, cb) Observe reactive path changes from GTPL state. instance.watch('foo', cb)
instance.destroy() Unmount elements, listeners and watchers. instance.destroy()

Security note: g-inner writes directly to innerHTML. Use trusted HTML sources only.