
Template details
Templix
HTML5-based PHP template engine with recursive extends and CSS3 selectors for DOM manipulation at compile time.
About this template
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.
What is Templix?
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.
Key Features
- Recursive extends — Templates can extend other templates that themselves extend layouts; the
<extend>markup chains through arbitrary levels and applies selector-based patches in order. - CSS3 selector DOM manipulation — Use jQuery/Sizzle-style selectors such as
find('a'),closest('form'), orchildren('img')to traverse and modify nodes at compile time. - PHP syntax as HTML5 markup — Control structures like
<if>,<foreach>,<switch>,<case>,<for>, and<else>are written as markup and compiled to PHP, with no need for<?phpblocks. - 50+ markup object methods — Methods include
append,prepend,remove,replaceWith,wrap,unwrap,attr,css,addClass,removeClass,data,tmpAttr,before,after, and array-style access via PHP magic methods. - Attribute and markup plugins — Built-in plugins cover caching (
cacheStatic,cacheSync), translation (t), variable assignment (var), and layout patching (write,apply,merge,submerge, and more). - onCompile binder — Register a callback that runs after the document is parsed and its full DOM is accessible, so you can apply global changes in PHP.
- XHTML output switching — Change the doctype from HTML5 to XHTML and the parser automatically outputs XHTML-compliant markup with the same templates.
- Custom plugin system — Build your own markup languages by extending
RedCat\Templix\Markupand mapping classes to tag names with a plugin prefix.
Who should use Templix?
- PHP developers building multi-page sites — Use recursive
<extend>to define a base layout and patch specific blocks (header, footer, content) from child templates. - Developers who prefer manipulating templates as DOM — If you like jQuery-style traversal, you can query and alter nodes with
find(),attr(), andaddClass()inside templates. - Teams needing legacy short-open-tag support — Templates can use
<?= ?>and similar syntax even when the server hasshort_open_tagdisabled. - Framework integrators — Because plugins are namespace-based and customizable, you can add your own template tags or integrate Templix into an existing PHP application.
What can you do with Templix?
- Layout inheritance with patches — Define
layout.xtmland use<extend>to load it, then override sections with<write>,<append>,<prepend>,<after>, and<before>selectors. - Form validation patching — Use
<apply>with a.tplpatcher file and the{{this:name}}syntax to inject error messages or default values into form fields automatically. - Fragment caching — Wrap expensive blocks in
<ul cacheSync="tracks">to cache them until a sync file is touched, or usecacheStaticto cache indefinitely. - Dynamic asset handling — Local
<img>,<script>, and<link>tags can automatically get height/width attributes for images and time-suffix parameters in dev mode to bust browser caches.
How does Templix work?
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().
Pros and cons
- Pro: Compiled output is a plain PHP include, so runtime overhead is minimal.
- Pro: Full DOM manipulation with CSS3 selectors makes template patching expressive.
- Pro: Recursive extends and the
applypatcher model are flexible for complex page layouts. - Con: The repository explicitly states it is no longer actively maintained; the author recommends moving to Node.js projects like ReactJS, Next.js, or EJS.
Alternatives
- Twig — a widely used PHP template engine with a sandboxed syntax and its own extension system.
- Blade — the template engine built into Laravel, offering layout inheritance and compiled views.
FAQ
Is Templix still maintained?
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.
Does Templix support PHP short-open-tags?
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.
How do I configure Templix paths?
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/'].
Can Templix output XHTML?
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.
What is the difference between <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.















