PHPackages                             rareloop/primer-template-engine-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. rareloop/primer-template-engine-twig

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

rareloop/primer-template-engine-twig
====================================

Twig template engine for Primer

v4.0.0(7y ago)05.6k—0%[3 issues](https://github.com/Rareloop/primer-template-engine-twig/issues)MITPHPPHP &gt;=7.0

Since Oct 12Pushed 7y ago8 watchersCompare

[ Source](https://github.com/Rareloop/primer-template-engine-twig)[ Packagist](https://packagist.org/packages/rareloop/primer-template-engine-twig)[ RSS](/packages/rareloop-primer-template-engine-twig/feed)WikiDiscussions master Synced 1mo ago

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

Twig Template Engine for Primer
===============================

[](#twig-template-engine-for-primer)

[![CI](https://camo.githubusercontent.com/115a7bb3b86e8adeb7e1f06d979dd2f64189f08a7bee3be735b22765b0da2884/68747470733a2f2f7472617669732d63692e6f72672f526172656c6f6f702f7072696d65722d74656d706c6174652d656e67696e652d747769672e737667)](https://camo.githubusercontent.com/115a7bb3b86e8adeb7e1f06d979dd2f64189f08a7bee3be735b22765b0da2884/68747470733a2f2f7472617669732d63692e6f72672f526172656c6f6f702f7072696d65722d74656d706c6174652d656e67696e652d747769672e737667)

A template engine for [Primer](http://github.com/rareloop/primer) that uses Twig rather than the deafult (Handlebars).

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

[](#installation)

1. In the `composer.json` in your Primer install, replace:

    ```
    "rareloop/primer-template-engine-handlebars": "dev-master"
    ```

    with:

    ```
    "rareloop/primer-template-engine-twig": "1.0.*"
    ```
2. Run `composer update`.
3. Modify your `bootstrap/start.php` file and change the `Primer::start` call to include the `templateClass` e.g.

    ```
    $primer = Primer::start(array(
        'basePath' => __DIR__.'/..',
        'templateClass' => Rareloop\Primer\TemplateEngine\Twig\Template::class,
    ));
    ```
4. Replace all `.hbs` files in your patterns and views with `.twig' files. If you don't want to do this by hand you can download the base Primer files in Twig format from [this repo](https://github.com/Rareloop/primer-patterns-twig).

Usage
-----

[](#usage)

### Including patterns within one another

[](#including-patterns-within-one-another)

Any pattern can be included within another by using the standard `include` syntax, e.g.

```

    {% include 'elements/forms/input' %}

```

More information on using `{% include %}` and manipulating the passed in context can be found on the [Twig website](http://twig.sensiolabs.org/doc/tags/include.html).

### Extending Templates

[](#extending-templates)

By default, Primer will wrap all page Templates with a common View (`views/template.twig`). When using `{% extends %}` this wrapping is sometimes undesirable, in such circumstances you can disable this behaviour in a couple of ways.

1. On a per page Template basis. Add the following to the Templates `data.json` file:

    ```
    {
        "primer": {
            "view": "custom-view"
        }
    }

    ```
2. Site wide. Add `wrapTemplate: false` to the `Primer::start` call in `bootstrap/start.php`, e.g.

    ```
    $primer = Primer::start([
        'basePath' => __DIR__.'/..',

        'templateClass' => TwigTemplateEngine::class,
        'wrapTemplate' => false,
    ]);
    ```

### Twig Template Cache

[](#twig-template-cache)

By default Primer uses a directory called `cache` inside the project root for cache files. To change this to somewhere else you can set an alternative when you start Primer in `bootstrap/start.php`, e.g.

```
$primer = Primer::start(array(
    'basePath' => __DIR__.'/..',
    'cachePath' => 'absolute/path/to/cache/dir',
    'templateClass' => Rareloop\Primer\TemplateEngine\Twig\Template::class,
));
```

### Custom Events

[](#custom-events)

Most of the Primer events are still available, this package adds a few engine specific events too:

- ### Twig Engine Initialisation

    [](#twig-engine-initialisation)

    Called when the Twig engine is created. Useful for registering custom helpers with the Twig engine.

    ```
    Event::listen('twig.init', function ($twig) {

    });
    ```

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 94.3% 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 ~191 days

Recently: every ~239 days

Total

6

Last Release

2836d ago

Major Versions

v1.0.2 → v2.0.02017-06-06

v2.0.0 → v3.0.02018-06-18

v3.0.0 → v4.0.02018-08-03

PHP version history (2 changes)v1.0.0PHP &gt;=5.5

v3.0.0PHP &gt;=7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1554376?v=4)[Rareloop](/maintainers/rareloop)[@Rareloop](https://github.com/Rareloop)

---

Top Contributors

[![joelambert](https://avatars.githubusercontent.com/u/644362?v=4)](https://github.com/joelambert "joelambert (33 commits)")[![adamtomat](https://avatars.githubusercontent.com/u/2631499?v=4)](https://github.com/adamtomat "adamtomat (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rareloop-primer-template-engine-twig/health.svg)

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

###  Alternatives

[twig/extra-bundle

A Symfony bundle for extra Twig extensions

91292.0M313](/packages/twig-extra-bundle)[twig/intl-extra

A Twig extension for Intl

36663.2M218](/packages/twig-intl-extra)[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[twig/string-extra

A Twig extension for Symfony String

21946.0M132](/packages/twig-string-extra)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

23018.5M53](/packages/twig-cssinliner-extra)[symfony/ux-twig-component

Twig components for Symfony

21814.8M161](/packages/symfony-ux-twig-component)

PHPackages © 2026

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