ttek / tk-domtemplate
PHP DomTemplate library
Fund package maintenance!
Requires
- php: ^8.3
- ext-dom: *
- ext-libxml: *
- ext-mbstring: *
- ext-tidy: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main / 9.0.x-dev
- 8.1.x-dev
- 8.1.0
- 8.0.x-dev
- 8.0.46
- 8.0.44
- 8.0.42
- 8.0.40
- 8.0.38
- 8.0.36
- 8.0.34
- 8.0.32
- 8.0.30
- 8.0.28
- 8.0.26
- 8.0.24
- 8.0.22
- 8.0.20
- 8.0.18
- 8.0.16
- 8.0.14
- 8.0.12
- 8.0.10
- 8.0.8
- 8.0.6
- 8.0.4
- 8.0.2
- 8.0.0
- 7.0.x-dev
- 3.2.x-dev
- 3.2.14
- 3.2.12
- 3.2.10
- 3.2.8
- 3.2.6
- 3.2.4
- 3.2.2
- 3.2.0
- 3.0.x-dev
- 3.0.38
- 3.0.36
- 3.0.34
- 3.0.32
- 3.0.30
- 3.0.28
- 3.0.26
- 3.0.24
- 3.0.22
- 3.0.20
- 3.0.18
- 3.0.16
- 3.0.14
- 3.0.10
- 3.0.8
- 3.0.6
- 3.0.4
- 3.0.2
- 3.0.0
- 2.2.64
- 2.2.62
- 2.2.60
- 2.2.58
- 2.2.56
- 2.2.54
- 2.2.52
- 2.2.50
- 2.2.48
- 2.2.46
- 2.2.44
- 2.2.42
- 2.2.40
- 2.2.38
- 2.2.36
- 2.2.34
- 2.2.32
- 2.2.30
- 2.2.28
- 2.2.26
- 2.2.24
- 2.2.22
- 2.2.20
- 2.2.18
- 2.2.16
- 2.2.14
- 2.2.12
- 2.2.10
- 2.2.8
- 2.2.6
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.14
- 2.0.13
- 2.0.12
- 2.0.11
- 2.0.10
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
This package is auto-updated.
Last update: 2026-11-11 00:12:54 UTC
README
Project: ttek/tk-domtemplate
Authors: Tropotek http://www.tropotek.com/
Documentation: https://tropotek.github.io/tk-domtemplate/
Warning
main is v9 (unreleased), a rewrite that is not backward compatible with 8.x.
Existing projects should stay on ^8.1 (branch 8.1).
See Upgrading from 8.x.
DomTemplate renders HTML templates from PHP without a template language. Layout and design stay in plain HTML that designers can open and edit. Render logic stays in PHP, which finds named nodes and fills them in.
- One
varattribute:var="name",var="name?"(removed unless shown),var="name[]"(a repeating row) - Chainable handles and one-line shortcuts
- Templates inserted into templates, rendered lazily with the page
- Scripts, styles, meta and title from any template, placed in
<head>, at the end of<body>or inline - Alpine.js and HTMX markup passes through untouched; HTMX fragments carry their own assets
- Selector-based modifiers, a component
Builder, and errors that throw in development and log in production
Requirements
- PHP 8.5+
ext-dom
Installation
composer require ttek/tk-domtemplate:9.0.x-dev
Basic usage
<!-- page.html --> <!doctype html> <html lang="en"> <head><title>Hello</title></head> <body> <h1 var="heading">Default heading</h1> <p var="admin?">Only admins see this.</p> <ul> <li var="item[]"><a var="link" href="#">Item</a></li> </ul> </body> </html>
<?php require __DIR__ . '/vendor/autoload.php'; use Tk\DomTemplate\Row; use Tk\DomTemplate\Template; $t = Template::file(__DIR__ . '/page.html'); $t->title('Hello World'); $t->text('heading', 'Hello World'); $t->show('admin', $user->isAdmin()); $t->each('item', $links, fn(Row $row, array $link) => $row->var('link')->text($link['label'])->attr('href', $link['url']) ); $t->cssUrl('/css/site.css'); echo $t->render();
Full documentation: https://tropotek.github.io/tk-domtemplate/
Running the examples
The example/ folder is a small Bootstrap site that shows each feature with its source.
It runs in a FrankenPHP container:
cp .env.example .env # set APP_HOST, HTTP_APP_PORT, APP_UID/APP_GID
docker compose up -d --build
Then open http://APP_HOST:HTTP_APP_PORT (http://127.0.0.1:8080 with the defaults).
Development
With the container running:
docker compose exec app composer check # phpstan + PHPUnit bin/e2e # browser tests of the example site (Playwright in Docker)
To release, add a Ver X.Y.Z [unreleased]: section to changelog.md, then run bin/release X.Y.Z.
It runs the checks, stamps the version and date, tags, and asks before pushing.
Contributing
If you wish to contribute updates to the code or documentation, we are open to any requests.
Use the GitHub discussions area to chat about what you would like to see or contribute.