PHPackages                             jinnguyen/puja-template - 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. jinnguyen/puja-template

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

jinnguyen/puja-template
=======================

Puja-Template is a lightweight, flexible and easy PHP template engine. Inspired in django, Puja also support validate template syntax!

v1.0.2(8y ago)0471The MIT License (MIT)PHP

Since Feb 11Pushed 8y ago1 watchersCompare

[ Source](https://github.com/jinnguyen/puja-template)[ Packagist](https://packagist.org/packages/jinnguyen/puja-template)[ RSS](/packages/jinnguyen-puja-template/feed)WikiDiscussions master Synced yesterday

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

Puja v1.1
=========

[](#puja-v11)

Puja is a lightweight, flexible and easy PHP template engine. Inspired in django, Puja also support validate template syntax!

**Install:**

```
composer require jinnguyen/puja-template
require '/path/to/vendor/autoload.php';

class CustomFilter extends \Puja\Template\Lexer\Filter\FilterAbstract
{
    public function dateFilter($var, $args) {
        return abs($var);
    }
}

class CustomTag extends \Puja\Template\Lexer\Tag\TagAbstract
{
    public function cssTag($arg)
    {
        return '';
    }

    public function javascriptTag($arg)
    {
        return '';
    }
}

$puja = new \Puja\Template\Template(array(
    /**
    * Folders that contain template files and the last folder is higher priority
    * Ex: templateDirs = ['/path/to/template/Default', '/path/to/template/2017'] and file test.tpl is in both /path/to/template/Default and /path/to/template/2017.
    * Then /path/to/template/2017/test.tpl (the last folder) will be used
    */
    'templateDirs' => [
      __DIR__ . '/templates/Default',
      __DIR__ . '/templates/2017'
    ],
    /**
    * Cached folder contains generated-files by Puja-Template
    */
    'cacheDir' => __DIR__ . '/cache/',
    /** Cache level, current we just support 3 levels
    * 0: no cache, (Puja-Template will re-generate every time)
    * 1: smart cache, (Puja-Template generate in the first time and ONLY re-genertate when file template (.tpl) has changed
    * 2: hard cache ( Puja-Template never re-generate files until genereted file has been deleted.)
    */
    'cacheLevel' => 0,
    /**
    * customTag class, default: NULL
    */
    'customTag' => 'CustomTag',
    /**
    * customFilter class, default: NULL
    */
    'customFilter' => 'CustomFilter',
    /**
    * On/off mode debug
    */
    'debug' => true,
));
```

**Some of Puja-Template's features**:

- **VALIDATE TEMPLATE SYNTAX**
- it is extremely fast
- no template parsing overhead, only compiles once.
- it is smart about recompiling only the template files that have changed.
- unlimited nesting of sections, conditionals, etc.
- built-in caching of template output.
- Smart access variable value, ex: {{ a.b }} will access like $a-&gt;b if $a is a obj, and $a\['b'\] if $a is array.

**Validate syntax:**
Puja support validate syntax before the parser run compiler. This will helpfull for you to write template syntax.

Bug list: [https://github.com/jinnguyen/puja/issues?page=1&amp;state=open](https://github.com/jinnguyen/puja/issues?page=1&state=open)

Example: file template: index.tpl:

```
{% extends master.tpl %}
{% block body %}
	Hello, {{ a }
	Welcome you go to Puja template examples
{% endblock %}
```

The result will be:

```

```

Puja only run debug when mode **debug** is enabled
\*\* We recommend you should only enable mode **debug** when your app is in develop. And disable it when your app go to production. It will save a lot time to template engine parser.

**Basic API Usage**:

- template file: index.tpl

```
Hello {{ username }},
Welcome you go to the very first exmplate of Puja template.
```

- php file: index.php

```
  $data = array(
  	'username'=>'Jin Nguyen',
  );
  $tpl->parse($template_file = 'index.tpl', $data);
```

The result will show:

```
Hello Jin Nguyen,
Welcome you go to the very first exmplate of Puja template.
```

See [User's guide](https://github.com/jinnguyen/puja/tree/master/docs/user-guide.md) for full information.

**Template Inheritance**:

- master.tpl:

```
==== Start Master ===
{% block body %}Master Body{% endblock body %}
{% block javascript %}Master javascript{% endblock javascript %}
==== End Master ====
```

- index.tpl

```
{% block javascript %}Index javascript [{{ block.supper }}]{% endblock %}
{% block body %}Index Body{% endblock %}
```

And the result will be:

```
==== Start Master ===
Index Body [Master Body]
Index javascript
==== End Master ====
```

[more detail &gt;&gt; ](https://github.com/jinnguyen/puja/tree/master/docs)

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

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

Every ~142 days

Total

3

Last Release

3142d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/25e5bd31b5dd70d47cbdc738bded06dbabfba3d584acce63c2c4b4fb7847f39d?d=identicon)[jinnguyen](/maintainers/jinnguyen)

---

Top Contributors

[![linhnmt](https://avatars.githubusercontent.com/u/10231628?v=4)](https://github.com/linhnmt "linhnmt (3 commits)")[![linhnnmt](https://avatars.githubusercontent.com/u/162856460?v=4)](https://github.com/linhnnmt "linhnnmt (1 commits)")

---

Tags

template enginephp template enginepujadjango styletemplate engine validate syntax

### Embed Badge

![Health badge](/badges/jinnguyen-puja-template/health.svg)

```
[![Health](https://phpackages.com/badges/jinnguyen-puja-template/health.svg)](https://phpackages.com/packages/jinnguyen-puja-template)
```

###  Alternatives

[phptal/phptal

PHPTAL is a templating engine for PHP5 that implements Zope Page Templates syntax

180436.7k20](/packages/phptal-phptal)[foil/foil

PHP template engine for native PHP templates

170112.3k10](/packages/foil-foil)[proai/laravel-handlebars

A Laravel wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

38206.9k](/packages/proai-laravel-handlebars)[talesoft/tale-pug

A clean, lightweight and easy-to-use templating engine for PHP based on Pug, formerly Jade

319.5k3](/packages/talesoft-tale-pug)[wanze/template-engine-factory

Provides ProcessWire integration for various template engines such as Twig.

2612.3k4](/packages/wanze-template-engine-factory)[leitsch/kirby-blade

Enable Laravel Blade Template Engine for Kirby 4 and Kirby 5

2110.1k](/packages/leitsch-kirby-blade)

PHPackages © 2026

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