Tinc is yet another template kit for PHP, a simple template system that conditionally-compiles Tinc pages to valid PHP, and provides some features I find it hard to do without.

The main design principle is cutting down on the number of assign()s typically done in template systems in order to bind variables to the template. With Tinc, you normally bind only one or two domain-model objects to the template, and use Tinc's enhanced variable navigation syntax.

To use Tinc, simply install the Tinc toolkit somewhere on your include_path, and

<?php
require_once 'Tinc.php';
?>

Then, anywhere you would use include(), use:

<?php
tinc('userProfile.php', array('user' => $someUser) );
?>

An example Tinc Template:

<html>
<head>
<title>User Profile - #{user.name}</title>
</head>
<body>
<h1>Profile - #{user.name}</h1>
Email: #{user.contactInfo.email} <BR>
Birthday: #{user.birthDay|date} <BR>
<?php foreach (${user.phoneNumbers} as $phone) { ?>
#{phone.type}: #{phone.number} <BR>
<?php } ?>
</body>
</html>

Here are the core features of Tinc:


- page syntax can be as simple as PHP with a few enhancements. All and any ordinary PHP works (as a result, this tookit is NOT for templating user input, it is for the view layer of an MVC style application).
- the variable scope of the page is limited to superglobals and variables passed in the optional second argument, no pollution of the global namespace.
- if you tinc() one page from another, relative paths are relative to the page doing the tinc(), NOT the script root or include_path
- sensible configuration defaults (tinc can be used with or without a configuration file)
- easy output with filters #{someVariable} or #{someDate|date} outside PHP code blocks, ${someVariable} etc. inside PHP code blocks. Lots of useful standard filters are included for formatting dates, numbers, strings.
- easy, consolidated object/array navigation (no more -> and []): e,g, #{person.contactInfo.email}. Supports 'getter' methods, straight property access, array keys/indexes, PHP5 magic __get method (even in PHP4). Navigation happens at runtime not compile time, so you can bind your domain model to the template and then dynamically/conditionally navigate it.
- supports PHP5 __toString() magic methods, even in PHP4, so #{someObject} will be equivalent to $someObject->__toString()
- optional extensible tag library support using the PEAR XML_HtmlSax library, designed to replace PHP code blocks with XML-style tags.

The distribution includes a PDF-based manual as well as PHPDoc docs.

Find out more and download Tinc (currently version 0.9.2) from my website: http://www.kahn.ca