PHPackages                             ttek/tk-domtemplate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. ttek/tk-domtemplate

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

ttek/tk-domtemplate
===================

PHP DomTemplate library

8.0.46(1mo ago)41.9k↓91.7%13MITPHPPHP ^8.3

Since Dec 9Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/tropotek/tk-domtemplate)[ Packagist](https://packagist.org/packages/ttek/tk-domtemplate)[ Fund](https://www.paypal.me/tropotek)[ RSS](/packages/ttek-tk-domtemplate/feed)WikiDiscussions 8.0 Synced 2w ago

READMEChangelogDependenciesVersions (113)Used By (3)

PHP DomTemplate 💥
=================

[](#php-domtemplate-boom)

**Project:** [ttek/tk-domtemplate](http://packagist.org/packages/ttek/tk-domtemplate)
**Authors:** Michael Mifsud
**Documentation:**

Introduction
------------

[](#introduction)

The PHP [\\Dom\\Template](http://domtemplate.tropotek.com/) wraps the DOMDocument and provides a fast, attribute-driven way to render HTML templates. We did not want another template language within a language, but a way to use PHP to render HTML templates keeping the render logic within PHP and the style and layout logic in HTML.

An important feature for us was the template layout and design were kept in the HTML so that it could be easily edited by designers and not be affected by what the developers in the team are doing. Making communication between developers and designers relatively easy for most tasks.

The \\Dom\\Template system enables developers to develop and share a basic markup structure, designers can then see visually and understand what the minimum markup requirements are. Saving on communication time and allowing designers to focus on making the project look great.

Features:

- Mark “variables” and “choices” in your HTML and set their content or visibility
- Manage repeating regions for table row insertion
- Insert/append/replace HTML fragments
- Add CSS/JS (inline or external) and meta/head elements
- Compose pages by merging templates, other DOMDocument's, or HTML strings

Key ideas:

- Use attributes in your HTML to mark nodes:
- var: mark nodes whose content/attributes you’ll set
- choice: mark nodes hidden that you can show in your renderer
- repeat: define repeating regions
- Work with the template (set text/HTML, attributes, headers) before parsing.
- Call `toString()` or `getDocument()` to parse the template and return a renderable DOMDocument or HTML string.

Installation
------------

[](#installation)

Available on Packagist ([ttek/tk-domtemplate](http://packagist.org/packages/ttek/tk-domtemplate)) and as such installable via [Composer](http://getcomposer.org/).

```
$ composer require ttek/tk-domtemplate
```

Or add the following to your composer.json file:

```
{
  "require": {
    "ttek/tk-domtemplate": "~8.0"
  }
}
```

Basic Template Usage
--------------------

[](#basic-template-usage)

```

  PHP Dom Template (PDT) Library

    Hello World
    Default Text

    &nbsp;
