PHPackages                             deniaz/terrific-twig - 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. deniaz/terrific-twig

Abandoned → [namics/terrific-twig](/?search=namics%2Fterrific-twig)ArchivedLibrary[Templating &amp; Views](/categories/templating)

deniaz/terrific-twig
====================

Extension to embrace the Terrific frontend methodology in Twig. Currently it adds a custom component tag to Twig which mimics Nitro's handlebars helper.

v1.0.0(9y ago)159MITPHPPHP &gt;=5.4

Since May 23Pushed 9y agoCompare

[ Source](https://github.com/deniaz/terrific-twig)[ Packagist](https://packagist.org/packages/deniaz/terrific-twig)[ Docs](https://github.com/namics/terrific-twig)[ RSS](/packages/deniaz-terrific-twig/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (5)Used By (0)

Terrific Twig
=============

[](#terrific-twig)

[![Build Status](https://camo.githubusercontent.com/d30d1394b3fa4a7cba5ac69817d4bae76e6fdd463bca36e59ed9200c4d1f6296/68747470733a2f2f7472617669732d63692e6f72672f6e616d6963732f74657272696669632d747769672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/namics/terrific-twig)[![Latest Stable Version](https://camo.githubusercontent.com/71fe2d15a23c17a7689493b2a82a8979437f6b9269276a0c390c4b8526e5dea5/68747470733a2f2f706f7365722e707567782e6f72672f6e616d6963732f74657272696669632d747769672f762f737461626c652e737667)](https://packagist.org/packages/namics/terrific-twig)[![Total Downloads](https://camo.githubusercontent.com/5177e507f78f354cdc4ce14273b3fa2c34dca100b52bfeeccbf0e65552eeaef9/68747470733a2f2f706f7365722e707567782e6f72672f6e616d6963732f74657272696669632d747769672f646f776e6c6f6164732e737667)](https://packagist.org/packages/namics/terrific-twig)[![License](https://camo.githubusercontent.com/a3bd31598fdee79e9e812e8c401ad3b793ff8fc73f367826e0d047c093772c8f/68747470733a2f2f706f7365722e707567782e6f72672f6e616d6963732f74657272696669632d747769672f6c6963656e73652e737667)](https://packagist.org/packages/namics/terrific-twig)

Extension to embrace the [Terrific](https://github.com/brunschgi/terrificjs) frontend methodology in [Twig](http://twig.sensiolabs.org/).

Currently it adds a custom `component` tag to Twig which mimics [Nitro](https://github.com/namics/generator-nitro)'s handlebars helper.

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

[](#installation)

Using [composer](https://packagist.org/packages/namics/terrific-twig):

```
$ composer require namics/terrific-twig
```

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

[](#requirements)

The following versions of PHP are currently supported.

- PHP 5.4 (**Deprecated**. Builds are failing since the tests are relying on [`::class`](http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.class.class).)
- PHP 5.5
- PHP 5.6
- PHP 7
- HHVM

Setup
-----

[](#setup)

Step 1: Implement `TemplateInformationProvider`

```
class TemplateInformationProvider implements TemplateInformationProviderInterface
{
    public function getPaths()
    {
      return []; // List of path where Terrific Components can be found, e.g. (/var/www/example.com/frontend/components)
    }

    public function getFileExtension()
    {
      $fileExtension = 'html.twig';
      return $fileExtension;
    }
}
```

Step 2: Implement `ContextProviderInterface`

```
class ContextProvider implements ContextProviderInterface
{
    public function compile(Twig_Compiler $compiler, Twig_Node $component, Twig_Node $dataVariant, $only) {
        // ...
    }
}
```

Step 3: Add `TerrificLoader`

```
$loader = ...;
$chain = new Twig_Loader_Chain([$loader, new TerrificLoader(new TemplateInformationProvider)]);
$twig = new Twig_Environment($chain);
```

Step 4: Add `TerrificExtension`

```
$twig = new Twig_Environment($chain);
$twig->addExtension(new TerrificExtension(new ContextProvider));
```

Step 5: Profit!

Usage
-----

[](#usage)

```
{# Includes the component, component's default data is merged with the context #}
{% component 'Example' %}

{# Includes the component, the default data is injected as a child context #}
{% component 'Example' only %}

{# Includes the component, but a variantion of the component data is merged with the context #}
{% component 'Example' 'example-variant' %}

{# Includes the component, but a variantion of the component data is injected as a child context #}
{% component 'Example' 'example-variant' only %}

{# Includes the component, data object is merged with the context #}
{% component 'Example' { title: 'Inject an Object' } %}

{# Includes the component, data object is injected as a child context #}
{% component 'Example' { title: 'Inject an Object' } only %}
```

Documentation
-------------

[](#documentation)

### Extension

[](#extension)

The extension provides terrific extensions to Twig. Currently the extension provides the `ComponentTokenParser`.

### Token Parser

[](#token-parser)

The token parser contains the parsing step for the component tag. It tokenizes the stream to different nodes (`component`, `data`) and an attribute (`only`).

The functionality is based on the fantastic `Twig_TokenParser_Include`.

### Node

[](#node)

The Node compiles the tokenized tag to PHP. To see some of the output, check the [`ComponentTest`](https://github.com/namics/terrific-twig/blob/master/test/Twig/Node/ComponentTest.php).

### Loader

[](#loader)

The `TerrificLoader` extends the `Twig_Loader_Filesystem` as it actually loads templates from the filesystem. An implementation of `TemplateLocatorInterface` provides the paths where the loader should search for templates.

### Template Information Provider

[](#template-information-provider)

An implementation of `TemplateInformationProviderInterface` should return a list of paths where templates live. These should be in the form of `['frontend/components/atoms', 'frontend/components/molecules', 'frontend/components/organisms']`. The component directory will be provided by the `TerrificLoader` (`Example/example.[ext]`).

### Context Provider

[](#context-provider)

This is the tricky part. An implementation of `ContextProviderInterface` decides which data will be made available to Twig templates. TODO: More on that.

### ConfigReader

[](#configreader)

Reads nitro's `config.json` and parses essential information such as the component paths and file extension.

Credits
-------

[](#credits)

- [Twig Template Engine](http://twig.sensiolabs.org/)
- [Terrific](http://terrifically.org/)
- [Terrific Micro](https://github.com/namics/terrific-micro)
- [Terrific Micro Twig](https://github.com/namics/terrific-micro-twig)
- [Nitro](https://github.com/namics/generator-nitro)

This project is partially sponsored by [Namics](https://github.com/namics).

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity61

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 ~57 days

Total

3

Last Release

3580d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/698963?v=4)[Robert](/maintainers/deniaz)[@deniaz](https://github.com/deniaz)

---

Top Contributors

[![deniaz](https://avatars.githubusercontent.com/u/698963?v=4)](https://github.com/deniaz "deniaz (9 commits)")

---

Tags

twigintegrationnitroterrificnamics

### Embed Badge

![Health badge](/badges/deniaz-terrific-twig/health.svg)

```
[![Health](https://phpackages.com/badges/deniaz-terrific-twig/health.svg)](https://phpackages.com/packages/deniaz-terrific-twig)
```

###  Alternatives

[symfony/ux-twig-component

Twig components for Symfony

22018.6M357](/packages/symfony-ux-twig-component)[symfony/ux-live-component

Live components for Symfony

1647.0M128](/packages/symfony-ux-live-component)[symfony/ux-toolkit

A tool to easily create a design system in your Symfony app with customizable, well-crafted Twig components

16126.1k1](/packages/symfony-ux-toolkit)[mati365/ckeditor5-symfony

CKEditor 5 integration for Symfony

262.6k](/packages/mati365-ckeditor5-symfony)

PHPackages © 2026

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