Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
HTML5-based PHP template engine with recursive extends and CSS3 selectors for DOM manipulation at compile time.
Templix is a PHP template engine from the RedCat PHP project that compiles HTML5/XML markup directly to PHP and exposes CSS3 selector DOM manipulation at compile time.
Templix takes template files written in an HTML5/XML syntax with embedded PHP and compiles them into plain PHP includes. It treats the template as a DOM, so you can query and modify it with jQuery/Sizzle-style selectors before output. The engine is developed as part of the RedCat PHP ecosystem and runs on any PHP environment with short-open-tag support built in (even when disabled in php.ini). Its output is a compiled PHP file that executes as fast as a simple include.
<extend> markup chains through arbitrary levels and applies selector-based patches in order.find('a'), closest('form'), or children('img') to traverse and modify nodes at compile time.<if>, <foreach>, <switch>, <case>, <for>, and <else> are written as markup and compiled to PHP, with no need for <?php blocks.append, prepend, remove, replaceWith, wrap, unwrap, attr, css, addClass, removeClass, data, tmpAttr, before, after, and array-style access via PHP magic methods.cacheStatic, cacheSync), translation (t), variable assignment (var), and layout patching (write, apply, merge, submerge, and more).RedCat\Templix\Markup and mapping classes to tag names with a plugin prefix.<extend> to define a base layout and patch specific blocks (header, footer, content) from child templates.find(), attr(), and addClass() inside templates.<?= ?> and similar syntax even when the server has short_open_tag disabled.layout.xtml and use <extend> to load it, then override sections with <write>, <append>, <prepend>, <after>, and <before> selectors.<apply> with a .tpl patcher file and the {{this:name}} syntax to inject error messages or default values into form fields automatically.<ul cacheSync="tracks"> to cache them until a sync file is touched, or use cacheStatic to cache indefinitely.<img>, <script>, and <link> tags can automatically get height/width attributes for images and time-suffix parameters in dev mode to bust browser caches.Templix parses a template into a DOM tree of PHP objects, applies plugins and selectors at compile time, then compiles the tree to a PHP file stored in a configured compile directory. On display, it simply includes that compiled file. You control paths with setDirCompile(), setDirCache(), and addDirCwd(), and you register callbacks with onCompile().
apply patcher model are flexible for complex page layouts.The repository header says No longer actively maintained and the author recommends ReactJS, Next.js, and EJS instead. There have been no updates indicated in the documentation.
Yes. Templix supports PHP short-open-tag syntax (such as <?= ?>) even when short_open_tag is not enabled in php.ini. The compiler rewrites the templates to valid PHP.
Use setDirCompile(), setDirCache(), setDirSync(), setDirCwd(), and addDirCwd() to set working, compile, cache, and sync directories. The defaults are .tmp/templix/compile/, .tmp/templix/cache/, .tmp/sync/, and ['template/','redcat/template/'].
Yes. If you change the HTML5 doctype <!DOCTYPE html> to an XHTML doctype, Templix automatically changes the output syntax to XHTML without modifying your templates. Void elements like <br>, <img>, and <input> are implicitly self-closed in HTML5 mode.
<include> and <incorpore>?<include> compiles a sub-template that is included via PHP's include, so the caller cannot manipulate the included template's DOM. <incorpore> embeds the sub-template into the caller's DOM completely, allowing both sides to modify each other's nodes.
