PHPackages                             watoki/tempan - 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. [Templating &amp; Views](/categories/templating)
4. /
5. watoki/tempan

ActiveLibrary[Templating &amp; Views](/categories/templating)

watoki/tempan
=============

Template animation engine using annotated HTML for PHP

v1.0(11y ago)2512.0k2MITPHPPHP &gt;=5.3.8

Since Nov 7Pushed 10y ago3 watchersCompare

[ Source](https://github.com/watoki/tempan)[ Packagist](https://packagist.org/packages/watoki/tempan)[ Docs](http://github.com/watoki/tempan)[ RSS](/packages/watoki-tempan/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

tempan [![Build Status](https://camo.githubusercontent.com/ccf76e12ba9535456991c03eb7caac9d3e79c203c1d08b599021b871ebffbc2b/68747470733a2f2f7472617669732d63692e6f72672f7761746f6b692f74656d70616e2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/watoki/tempan)
=============================================================================================================================================================================================================================================================================

[](#tempan-)

*tempan* is a template engine which uses annotated HTML to render data provided by a view model.

Purpose
-------

[](#purpose)

This project was inspired by Iain Dooleys post on [workingsoftware.com](http://www.workingsoftware.com.au/page/Your_templating_engine_sucks_and_everything_you_have_ever_written_is_spaghetti_code_yes_you). In his post, Iain argues that "As soon as I'm looking at more than one programming or markup language in the same file, I'm looking at spaghetti code." He refers to the mix-up of a templating language and HTML with most templating engines. He suggests that instead one should use HTML itself to bear the meta-data needed to manipulate the HTML on DOM level. He calls this *Template Animation*, hence the name of this project.

The main advantage is the template resulting to be completely independent of the rendering engine. Instead of creating a template with all kind of curly placeholders, the markup looks like this

```

	Name: John Wayne
	Homepage:
		johnwayne.com

```

The `property` attributes refer to the field names of the view model below. This attribute is also used in the *Resource Description Framework in attributes* or [RDFa](http://rdfa.info/), hence the template can be easily extended to become a RDFa document.

```
{
	"Person": {
		"name": "John Wayne",
		"url" : {
			"href": "http://johnwayne.com",
			"caption": "johnwayne.com"
		}
	}
}

```

Main Features
-------------

[](#main-features)

The feature set includes conditionals, repetition and dynamic values. This makes the *tempan* both compact and powerful.

*Note*: Although JSON syntax is used to describe the view models, they are actually PHP objects or arrays.

### Replace content with static values

[](#replace-content-with-static-values)

The text content and attributes of an element are replaced with the value of the view model matching the attributes name in the `property` attribute.

```
{
	"one": "Hello",
	"two": {
		"value": "World",
		"title": "Everyone"
	}
}

```

leads to

```
Hello
World

```

### Navigate complex data

[](#navigate-complex-data)

Nested data structures can be traversed as well. To access the inner data of the following view model

```
{
	"recipient": "World"
	"outer": {
		"inner": {
			"message": "Hello"
		}
	}
}

```

the template would be

```

		Hello
		World

```

The scope of the properties is not limited to the current sub-model but inherited by the containing models. In this example, `recipient` is inherited by the models grand-father. However, the scope of attributes is limited to the current model.

### Replace content with dynamic values

[](#replace-content-with-dynamic-values)

The referenced data may be the return value of a method or closure. Only zero-arguments methods are possible. Closures receive the current element and instance on `Animator` as their arguments. This way, variables can be generated on-demand and element modified dynamically.

```
{
	"number": {
		"value": 2,
		"isMany": function (element, animator) { return this.value != 1 },
		"shorten": function (element, animator) { return element->getContent()->substr(0, 4); }
	}
}

```

can be used with

```

	2 cars
	Some long string

```

### Remove elements

[](#remove-elements)

If the value is `false`, `null`, an empty array, the corresponding element will be removed. If the value is `true`, the element won't be modified but its children. An undefined propery is ignored.

### Repeated elements

[](#repeated-elements)

If the value of a field is a list, the element will be repeated for each item of the list.

```
{
	"pets": {
		"isMany": true,
		"count": 2,
		"pet": [
			{ "name": "Cat" },
			{ "name": "Dog" }
		]
	}
}

```

Siblings of the element in the template will be removed before repeating the element. Thus the following rendered result can be used as its template as well.

```

		I have 2 pets

			Cat

			Dog

```

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

[](#installation)

There are three options. If you already have [Composer](http://getcomposer.org/), you can use

```
php composer.phar create-project watoki/tempan

```

to check out *tempan* as a stand-alone project (you'll need git and php as well). To run the test suite use

```
cd tempan
phpunit

```

If you don't have Composer yet, or want to install a different branch you can use

```
git clone https://github.com/watoki/tempan.git
cd tempan
php install.php

```

To use it in your own project, add the following lines to your `composer.json`.

```
"require" : {
    "watoki/tempan" : "*"
},
"minimum-stability": "dev"

```

Basic Usage
-----------

[](#basic-usage)

For a complete description of all features and usage examples, check out the test cases in the [spec](https://github.com/watoki/tempan/tree/master/spec/watoki/tempan) folder. You can find an example using all the basic features together in [ComplexTest.php](https://github.com/watoki/tempan/tree/master/spec/watoki/tempan/ComplexTest.php).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4208d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e687108526c164e4ad1c49b8228514541bd90d43ef70665a087d00e34a1f7559?d=identicon)[rtens](/maintainers/rtens)

---

Top Contributors

[![rtens](https://avatars.githubusercontent.com/u/1468866?v=4)](https://github.com/rtens "rtens (43 commits)")[![theseer](https://avatars.githubusercontent.com/u/111333?v=4)](https://github.com/theseer "theseer (2 commits)")

---

Tags

templaterdfawatokitemplate animation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/watoki-tempan/health.svg)

```
[![Health](https://phpackages.com/badges/watoki-tempan/health.svg)](https://phpackages.com/packages/watoki-tempan)
```

###  Alternatives

[phpoffice/phpword

PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)

7.5k34.7M186](/packages/phpoffice-phpword)[rize/uri-template

PHP URI Template (RFC 6570) supports both expansion &amp; extraction

420137.3M46](/packages/rize-uri-template)[mopa/bootstrap-sandbox-bundle

Seperate live docs from code

256.8k](/packages/mopa-bootstrap-sandbox-bundle)[larablocks/pigeon

A more flexible email message builder for Laravel 5 including chained methods, reusable message configurations, and message layout and template view management.

143.7k](/packages/larablocks-pigeon)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
