Recent

Author Topic: PasTemplates - a go-like templates engine  (Read 278 times)

CynicRus

  • Jr. Member
  • **
  • Posts: 62
PasTemplates - a go-like templates engine
« on: January 22, 2026, 05:35:57 pm »
Hello again! :) I'm releasing a template engine for FPC + LAzarus under a BSD-3-Clause license.
FPC 3.1.1 is required. It supports all the key templating features of Go: logical constructs ({{if}}, {{with}}), iterations ({{range}}), nested templates ({{define}}/{{template}}), and the advanced {{block}} layout function for creating layout systems. The engine works with objects, arrays, and collections via RTTI, supports user-defined functions, HTML escaping ({{html .}}), loading templates from files, and customizing behavior when fields are missing (missingkey=error). And much more: you can generate all sorts of emails, documentation, settings—basically, whatever your imagination allows. I developed it as part of the system, but it's probably ripe for a life of its own. Examples are in examples, tests are in tests. Otherwise, it's ready to go. Just connect LazUtils + TemplateRuntime and you're ready to use. Download it here:

https://github.com/CynicRus/PasTemplates

Feature list:

  • Full Go text/template syntax (including {{block}}, {{range}}, {{with}}, pipelines, etc.)
  • Runtime-safe access to objects, arrays, and collections via RTTI
  • Built-in functions (len, index, eq, and, or, not, print, call, etc.)
  • User-defined functions
  • HTML auto-escaping ({{html .}})
  • Template composition and inheritance ({{define}}, {{template}}, {{block}})
  • File-based template loading
  • Configurable missing-key behavior (error / zero / invalid)
  • Whitespace trimming ({{- and -}})
  • Comments ({{/* ... */}})

 

TinyPortal © 2005-2018