PHPackages                             webiny/template-engine - 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. webiny/template-engine

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

webiny/template-engine
======================

Webiny Template Engine Component

v1.6.1(8y ago)1441MITPHPPHP ^7

Since Sep 20Pushed 8y ago10 watchersCompare

[ Source](https://github.com/Webiny/TemplateEngine)[ Packagist](https://packagist.org/packages/webiny/template-engine)[ Docs](http://www.webiny.com/)[ RSS](/packages/webiny-template-engine/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (6)Versions (23)Used By (1)

Template Engine Component
=========================

[](#template-engine-component)

`TemplateEngine` component provides a layer for rendering view templates.

Install the component
---------------------

[](#install-the-component)

The best way to install the component is using Composer.

```
composer require webiny/template-engine
```

For additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/template-engine).

### Installation error

[](#installation-error)

If you get an error like this:

```
[RuntimeException]
Package could not be downloaded, sh: 1: svn: not found

```

Then probably you don't have Subversion installed which is preventing the installation of Smarty library. This can be easily solved by installing the Subversion, prior to the composer install.

```
$ sudo apt-get install subversion

```

Usage
-----

[](#usage)

The definition of the view template depends on the selected driver. By default the template engine comes with a driver for `Smarty`, but you can easily add support for `Twig` or some other template engines.

The provided functionality of every driver is defined by the `TemplateEngineInterface` which defines the following methods:

- **fetch** - fetch the template from the given location, parse it and return the output
- **render** - fetch the template from the given location, parse it and output the result to the browser
- **assign** - assign a variable and its value into the template engine
- **setTemplateDir** - directory where the template files are stored
- **registerPlugin** - register a plugin for the template engine

To create a new driver just create a new class that implements the `\Webiny\Component\TemplateEngine\Bridge\TemplateEngineInterface`and adapt your config.

The default configuration looks like this:

```
    TemplateEngine:
        Engines:
            Smarty:
                ForceCompile: false
                CacheDir: '/var/tmp/smarty/cache'
                CompileDir: '/var/tmp/smarty/compile'
                TemplateDir: '/var/www/theme/templates'
                AutoEscapeOutput: false
                MuteExpectedErrors: true
```

Usage
-----

[](#usage-1)

The preferred usage is over the `TemplateEngineTrait`. Here is an example:

```
class MyClass
{
	use \Webiny\Component\TemplateEngine\TemplateEngineTrait;

	function __construct() {
	    // assing name and id to the template and render it
		$this->templateEngine('Smarty')->render('template.tpl', ['name'=>'John', 'id'=>15]);
	}
}
```

### Smarty

[](#smarty)

If you wish to use the Smarty template engine, with the built in driver, make sure you include `path/to/Smarty/libs/Smarty.class.php` somewhere inside you application, before using the component. This is due to the problem that Smarty doesn't provide a suitable autoloader to be integrated with the component.

Plugins &amp; extensions
------------------------

[](#plugins--extensions)

The template engine is designed so that it can be expanded with different plugins and modifiers, depending on the assigned driver.

Best practice for expanding the template engine is first to create an extension and then register it as a service tagged with the `$driverName.Extension`, for example `Smarty.Extension`.

An `Extension` is a package of one or multiple plugins. Plugin type depends on the template engine, for example, Smarty supports these plugin types:

- **functions** -
- **modifiers** -
- **blocks** -
- **compiler functions** -
- **pre filters** -
- **post filters** -
- **output filters** -
- **resources** -
- **inserts** -

To create a smarty extension, create a class that extends `\Webiny\Component\TemplateEngine\Drivers\Smarty\AbstractSmartyExtension`and then overwrite the methods, based on the plugin type your wish to create.

For example, let's say we want to register a modifier called 'customUpper'. First we create our extension class like this:

```
namespace MyApp\Demo;

class MySmartyExtension extends \Webiny\Component\TemplateEngine\Drivers\Smarty\SmartyExtension
{
	/**
	 * @overwrite
	 * @return array
	 */
	function getModifiers(){
		return [
			new SmartySimplePlugin('custom_upper', 'modifier', [$this, 'customUpper'])
		];
	}

	/**
	 * Callback for my custom_upper modifier.
	 *
	 * @param $params
	 *
	 * @return string
	 */
	function customUpper($params){
		return strtoupper($params);
	}

	/**
	 * Returns the name of the plugin.
	 *
	 * @return string
	 */
	function getName() {
		return 'my_extension';
	}
}
```

Once we have our extension, we must register it using the service manager:

```
MyApp:
    CustomExtension:
        Class: \MyApp\Demo\MySmartyExtension
        Tags: [Smarty.Extension]
```

And that's it, we can now use the modifier in our templates:

```
{'this is my name'|custom_upper}
// outputs: THIS IS MY NAME
```

Resources
---------

[](#resources)

To run unit tests, you need to use the following command:

```
$ cd path/to/Webiny/Component/TemplateEngine/
$ composer.phar install
$ phpunit

```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity73

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~52 days

Recently: every ~5 days

Total

22

Last Release

3153d ago

PHP version history (3 changes)1.0.x-devPHP &gt;=5.4.0

1.2.x-devPHP &gt;=5.5.9

1.5.x-devPHP ^7

### Community

Maintainers

![](https://www.gravatar.com/avatar/4440afa738ed146b05c06073a90345e0464c4f4d042b039532d881ca24859d77?d=identicon)[SvenAlHamad](/maintainers/SvenAlHamad)

---

Top Contributors

[![SvenAlHamad](https://avatars.githubusercontent.com/u/3808420?v=4)](https://github.com/SvenAlHamad "SvenAlHamad (21 commits)")

---

Tags

smartytemplate engineviews

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/webiny-template-engine/health.svg)

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

###  Alternatives

[ytake/laravel-smarty

Smarty template engine for Laravel and Lumen

87401.6k](/packages/ytake-laravel-smarty)[noiselabs/smarty-bundle

This Symfony bundle provides integration for the Smarty3 template engine.

53194.4k1](/packages/noiselabs-smarty-bundle)[talesoft/tale-pug

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

319.4k3](/packages/talesoft-tale-pug)[latrell/smarty

This package lets you run Smarty3 on Laravel5 elegantly.

127.0k](/packages/latrell-smarty)

PHPackages © 2026

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