Twig is a mature, feature-rich template engine for PHP that compiles templates to optimized PHP code. It employs a lexer-parser-compiler pipeline to transform template source into an abstract syntax tree (AST), which is then compiled to executable PHP. The engine emphasizes security through automatic escaping and a sandboxing system, and extensibility via a robust extension system that allows adding custom functions, filters, tests, and token parsers. Twig supports template inheritance, macros, and expressive syntax with features like null-safe operators and arrow functions. The architecture is modular and follows several well-established patterns: a plugin-based expression parser, a decorator-pattern caching system, a visitor pattern for AST manipulation, and an attribute-driven extension registration mechanism (using PHP 8+ attributes). The codebase demonstrates careful attention to extensibility, security, and performance, with comprehensive test coverage and active maintenance. While the project manages significant backward compatibility (notably preparing for Twig 4.0), it maintains a clean separation of concerns and provides reusable components that could be adapted for other projects, such as its chainable cache, expression parser registry, and sandbox security policy.
HMPL.js is a lightweight JavaScript library for server-oriented HTML templating. It compiles templates with block helpers (e.g., `{{#request ...}}`) into functions that fetch HTML from a server, sanitize it via DOMPurify, and render it into the DOM. The library supports indicators, memoization, intervals, and status binding, and uses JSON5 for expressive attribute parsing. The core is a single TypeScript module (`src/main.ts`) that exports `compile`, `stringify`, `createWarning`, and `createError`. The repository also contains a comprehensive documentation site built with Astro + Starlight (including Vue interactive components) and a Jekyll blog. The codebase is well-tested with Mocha, Sinon, nock, and jsdom, and has CI/CD via GitHub Actions. It is primarily a frontend library but includes robust build and test infrastructure.