PHPackages                             mindplay/kisstpl - 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. mindplay/kisstpl

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

mindplay/kisstpl
================

View service / template engine for plain PHP templates

1.3.3(8y ago)448.3k↓22.7%[1 issues](https://github.com/mindplay-dk/kisstpl/issues)1LGPL-3.0+PHPPHP &gt;=5.3

Since Feb 19Pushed 8y ago1 watchersCompare

[ Source](https://github.com/mindplay-dk/kisstpl)[ Packagist](https://packagist.org/packages/mindplay/kisstpl)[ RSS](/packages/mindplay-kisstpl/feed)WikiDiscussions master Synced 1mo ago

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

mindplay/kisstpl
----------------

[](#mindplaykisstpl)

[![PHP Version](https://camo.githubusercontent.com/3defa515920750802a17f1973ac80f3f8d2f03f68b58fd1dfe672528243bfa21/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d352e332532422d626c75652e737667)](https://packagist.org/packages/mindplay/kisstpl)[![Build Status](https://camo.githubusercontent.com/96db7ee46b176cd6a2e6af36b55b3434780661e4f85be4ba75f4b373071c98eb/68747470733a2f2f7472617669732d63692e6f72672f6d696e64706c61792d646b2f6b69737374706c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mindplay-dk/kisstpl)[![Code Coverage](https://camo.githubusercontent.com/05486425b21ae22334607a3d16896db0d7391425d5c38a2e468f4a9b8e4fae1a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d696e64706c61792d646b2f6b69737374706c2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mindplay-dk/kisstpl/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3e82004d9f770f9978402a542b393332e9b1b182c86fd706756dca30c04921eb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d696e64706c61792d646b2f6b69737374706c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mindplay-dk/kisstpl/?branch=master)

A very simple view-service / template-engine for plain PHP templates.

I wanted a template engine that uses view-models (objects) rather than view-dictionaries (arrays) as are typical in most PHP template engines.

Oh, and if you don't like typing `htmlspecialchars()` all day, maybe try [this](https://github.com/mindplay-dk/escape).

The view-service is tied to a root folder and a root namespace:

```
$service = new ViewService(new SimpleViewFinder('my/app/views', 'app\view'));

$hello = new \app\view\HelloWorld();

$service->render($hello); // -> "my/app/views/HelloWorld.view.php"
```

The `render()` statement in this example will render the template `my/app/views/HelloWorld.view.php`, passing the view-model object to the rendered template as `$view` - the `SimpleViewFinder` is responsible for locating the actual template based on the type of view-model.

The `render()` method also accepts a second argument, allowing you to render different templates for the same view-model:

```
$service->render($hello, 'boom'); // -> "my/app/views/HelloWorld.boom.php"
$service->render($hello, 'bang'); // -> "my/app/views/HelloWorld.bang.php"
```

You can type-hint in the beginning of a template file for IDE support:

```

...
```

Alternatively, for type-safe template rendering, you can also type-hint statically, by returning a closure:

```
use app\view\HelloWorld;
use mindplay\kisstpl\Renderer;

...
