PHPackages                             silent/twig-const-resolver - 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. silent/twig-const-resolver

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

silent/twig-const-resolver
==========================

Simple Twig plugin to resolve constant on template cache build

1.1.1(10y ago)129.3k1MITPHPPHP &gt;=5.6.0

Since Sep 7Pushed 10y ago2 watchersCompare

[ Source](https://github.com/silentroach/twig-const-resolver)[ Packagist](https://packagist.org/packages/silent/twig-const-resolver)[ Docs](https://github.com/silentroach/twig-const-resolver)[ RSS](/packages/silent-twig-const-resolver/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (3)Versions (7)Used By (0)

Twig Constant Resolver Extension
================================

[](#twig-constant-resolver-extension)

[![Packagist](https://camo.githubusercontent.com/3cb4f236889c63cb67c4d793301125c55492d3dbced85c9936313704baf754e6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73696c656e74726f6163682f747769672d636f6e73742d7265736f6c7665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/silent/twig-const-resolver)[![Travis](https://camo.githubusercontent.com/b61a3ecfe095e5c53224a6c96000a5afa351eb2c64fa4313a27cf4082d617d9c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f73696c656e74726f6163682f747769672d636f6e73742d7265736f6c7665722e7376673f7374796c653d666c61742d737175617265266c6162656c3d747261766973)](https://travis-ci.org/silentroach/twig-const-resolver)[![Coveralls](https://camo.githubusercontent.com/ccf418e9df0a330d0308608aa66350f1f58581ac34632d932b3cd0940c0298e2/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f73696c656e74726f6163682f747769672d636f6e73742d7265736f6c7665722e7376673f7374796c653d666c61742d737175617265266c6162656c3d636f766572616765)](https://coveralls.io/r/silentroach/twig-const-resolver)

Simple Twig plugin to resolve constant on template cache build.

Why
---

[](#why)

For example we have something like this:

```
{% if usertype == constant('Users::TYPE_TROLL') %}
    Bye-bye
{% else %}
    Hello!
{% endif %}
```

Without this extension Twig will compile it in something like this:

```
if (((isset($context["usertype"]) ? $context["usertype"] : null) == twig_constant("Users::TYPE_TROLL"))) {
    // twig_constant will be evaluated in runtime
    echo "Bye-bye";
} else {
    echo "Hello";
}
```

It will be compiled even if you have no constant with that name. So you will get an error in production.

With this extension you can avoid this types of errors cause it will evaluate constants at the build step, so this template will be compiled in something like this:

```
if (((isset($context["usertype"]) ? $context["usertype"] : null) == Users::TYPE_TROLL)) {
    // constant is resolved at the build step (Users::TYPE_TROLL)
    echo "Bye-bye";
} else {
    echo "Hello";
}
```

Also in evaluation mode it can be compiled in something like this:

```
if (((isset($context["usertype"]) ? $context["usertype"] : null) == 2)) {
    // constant is resolved and evaluated at the build step (Users::TYPE_TROLL => 2)
    echo "Bye-bye";
} else {
    echo "Hello";
}
```

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

[](#installation)

The extension is installable via composer:

```
{
    "require": {
        "silent/twig-const-resolver": "~1.1"
    }
}
```

Setup
-----

[](#setup)

```
$twig->addExtension(
    /**
     * @param $evaluate bool Evaluate consts (default: false)
     */
    new \silent\Twig\ConstantResolverExtension\Extension()
);
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 92.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 ~9 days

Total

6

Last Release

3862d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.6.0

1.0.2PHP &gt;=5.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/ae8efef879be9e3d9de8607afc907c77fb3812fbd188e3b407dba26c5dc2a1f9?d=identicon)[silent](/maintainers/silent)

---

Top Contributors

[![silentroach](https://avatars.githubusercontent.com/u/166803?v=4)](https://github.com/silentroach "silentroach (24 commits)")[![dimarick](https://avatars.githubusercontent.com/u/2605934?v=4)](https://github.com/dimarick "dimarick (2 commits)")

---

Tags

twigtemplatingextensionconstant

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/silent-twig-const-resolver/health.svg)

```
[![Health](https://phpackages.com/badges/silent-twig-const-resolver/health.svg)](https://phpackages.com/packages/silent-twig-const-resolver)
```

###  Alternatives

[timber/timber

Create WordPress themes with beautiful OOP code and the Twig Template Engine

5.7k3.4M111](/packages/timber-timber)[shoot/shoot

Shoot aims to make providing data to your templates more manageable

40229.9k2](/packages/shoot-shoot)[redant/twig-components

Define reusable components in Twig.

3819.8k1](/packages/redant-twig-components)

PHPackages © 2026

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