PHPackages                             tpawl/lite - 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. tpawl/lite

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

tpawl/lite
==========

Lightweight Template Engine

v1.5.0(7y ago)024MITPHPPHP &gt;=7.1.0

Since Mar 20Pushed 4y agoCompare

[ Source](https://github.com/tpawl/LiTE)[ Packagist](https://packagist.org/packages/tpawl/lite)[ Docs](https://github.com/tpawl/LiTE)[ RSS](/packages/tpawl-lite/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (1)Versions (13)Used By (0)

LiTE
====

[](#lite)

**Li**ghtweight **T**emplate **E**ngine

[![Build Status](https://camo.githubusercontent.com/047a2677a4fe220a7a5cbb75505df5bd96a13b9eb20e19f688bb1d590b0a7266/68747470733a2f2f7472617669732d63692e6f72672f747061776c2f4c6954452e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/tpawl/LiTE)[![Coverage Status](https://camo.githubusercontent.com/dd7fa83e41f12f8e4b678556c1e6cafdadb443f90c24e12f4b3f3d6b8324a7aa/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f747061776c2f4c6954452f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/tpawl/LiTE?branch=master)

Description
-----------

[](#description)

**LiTE** is an ad hoc Template Engine especially suited for Backends. It is native, because it uses PHP as its Template Language and needs no compiling of templates. It supports Template Variables and View Helpers.

Requirements
------------

[](#requirements)

**LiTE** requires PHP 7.3+

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

[](#installation)

Via Composer

```
$ composer require tpawl/lite
```

Usage
-----

[](#usage)

### LiTE for Developers

[](#lite-for-developers)

#### Basics

[](#basics)

The heart of **LiTE** is a object called the **template expression** (of class `TPawl\LiTE\Expressions\TemplateExpression`).

A template expression object is created like this:

```
$settings = [
    $template, // a string holding the template
    ['the' => 'variables', 'go' => 'here'],
    '/path/to/view_helpers',
    'view_helpers\namespace',
];

$templateExpression = new TPawl\LiTE\Expressions\TemplateExpression($settings);
```

This will create a template expression that looks up the view helpers in the `/path/to/view_helpers/` folder.

Note that the only argument of the template expression is an array of settings options.

- The first option is the template as a string.
- The second option is an associative array of template variables, with the name of the variable as the key and its value.
- The third option is the path to the folder in which the view helpers are stored.
- The fourth option is the namespace in which the view helpers are defined as a string. If you do not use a namespace for your view helpers, write the empty string (`''`) here.

#### Outputting the template

[](#outputting-the-template)

```
$templateExpression->display();
```

#### Defining a view helper

[](#defining-a-view-helper)

A view helper is a class that implements the interface `TPawl\LiTE\ViewHelperInterface`, that has a static `execute` method. The name of that class must be ending with `ViewHelper` and the first letter must be upper-case. The code for this class must be saved in a file with the name of the corresponding class with a trailing `.php`. This file must be stored in a folder given as the third configuration option of the template expression.

Example:

```
`. It is useful if you want to output XML.

Example
-------

[](#example)

Save the following view helper to a file named `MsgViewHelper.php` in any folder:

```
