PHPackages                             davidphtee/templiphy - 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. davidphtee/templiphy

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

davidphtee/templiphy
====================

A simple PHP template engine with moustache syntax: {{ $variable }} and {{{ PHP code }}}.

01PHP

Since Jun 17Pushed 11mo agoCompare

[ Source](https://github.com/davidphtee/TempliPHy)[ Packagist](https://packagist.org/packages/davidphtee/templiphy)[ RSS](/packages/davidphtee-templiphy/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

TempliPHy - a Simple PHP Template Engine
========================================

[](#templiphy---a-simple-php-template-engine)

A lightweight PHP template engine with moustache syntax for easy variable insertion and PHP code execution within your HTML templates.

---

Features
--------

[](#features)

✅ **Moustache Syntax**

- `{{ $variable }}` — Outputs a variable’s value
- `{{{ PHP code }}}` — Executes raw PHP code

✅ **Development &amp; Production Modes**

- Development mode uses a temporary file for better error tracing.
- Production mode uses `eval()` for faster rendering.

✅ **Safe Variable Handling**

- Variables are extracted safely.
- Errors are handled gracefully with meaningful messages.

---

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

[](#installation)

Simply include `Template.php` in your project.

```
require_once 'Template.php';
```

---

Usage
-----

[](#usage)

### 1️⃣ Create a Template instance

[](#1️⃣-create-a-template-instance)

```
$template = new Template(true); // `true` enables development mode
```

---

### 2️⃣ Set variables

[](#2️⃣-set-variables)

```
$template->set('title', 'Hello World');
$template->setArray([
    'name' => 'John',
    'age' => 30
]);
```

---

### 3️⃣ Create a template file

[](#3️⃣-create-a-template-file)

**example.tpl**

```
{{ $title }}
Name: {{ $name }}
Age: {{ $age }}

{{{ if($age >= 18): }}}
Access granted.
{{{ else: }}}
Access denied.
{{{ endif; }}}
```

---

### 4️⃣ Render the template

[](#4️⃣-render-the-template)

```
echo $template->fetch('example.tpl');
```

---

Configuration
-------------

[](#configuration)

ParameterDescription`isDevelopment``true` (default): uses a temporary file for detailed error tracing.
 `false`: uses `eval()` for faster rendering in production.---

Class Reference
---------------

[](#class-reference)

### `__construct(bool $isDevelopment = true)`

[](#__constructbool-isdevelopment--true)

Create a new instance.

- `true` → development mode
- `false` → production mode

### `set(string $name, mixed $value)`

[](#setstring-name-mixed-value)

Set a single variable.

### `setArray(array $list)`

[](#setarrayarray-list)

Set multiple variables at once.

### `fetch(string $file): string`

[](#fetchstring-file-string)

Render the given template file with the current variables.

---

Error Handling
--------------

[](#error-handling)

- Throws `RuntimeException` if:
    - The template file does not exist or is unreadable.
    - An error occurs while rendering the template.
- In development mode, the source file name and line numbers are preserved for easier debugging.

---

License
-------

[](#license)

MIT — use it freely!

---

Author
------

[](#author)

**David Tee**

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2fca3788b89ce7f71b439f71820e8693d1eb3a43b741015a8c773e06846f3367?d=identicon)[davidphtee](/maintainers/davidphtee)

---

Top Contributors

[![davidphtee](https://avatars.githubusercontent.com/u/22905624?v=4)](https://github.com/davidphtee "davidphtee (5 commits)")

### Embed Badge

![Health badge](/badges/davidphtee-templiphy/health.svg)

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

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)

PHPackages © 2026

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