PHPackages                             uuf6429/expression-language-tplstring - 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. uuf6429/expression-language-tplstring

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

uuf6429/expression-language-tplstring
=====================================

Template String support for Symfony Expression Language

2.1.0(1mo ago)17.0k1MITPHPPHP ^7.4 || ^8CI passing

Since Jul 17Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/uuf6429/expression-language-tplstring)[ Packagist](https://packagist.org/packages/uuf6429/expression-language-tplstring)[ Docs](https://github.com/uuf6429/expression-language-tplstring)[ RSS](/packages/uuf6429-expression-language-tplstring/feed)WikiDiscussions main Synced 1w ago

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

🪡 Template Strings
==================

[](#-template-strings)

for Symfony Expression Language (5-8)

[![CI](https://github.com/uuf6429/expression-language-tplstring/actions/workflows/ci.yml/badge.svg)](https://github.com/uuf6429/expression-language-tplstring/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/64ac34904f5598214da5180e0720bf7baf7633399ba81beb4f041cbd4af3381e/68747470733a2f2f636f6465636f762e696f2f67682f757566363432392f65787072657373696f6e2d6c616e67756167652d74706c737472696e672f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/uuf6429/expression-language-tplstring)[![Minimum PHP Version](https://camo.githubusercontent.com/b4c5b22c5d4b22afa104d352e9212e63318131d682168261e127b6f9f570cbea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545372e34253230253743253230253545382d3838393242462e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/b1d9e94ec75783931141c741c3ee72dfa6c0586bf990ce83268a6a7ff5d60011/68747470733a2f2f706f7365722e707567782e6f72672f757566363432392f65787072657373696f6e2d6c616e67756167652d74706c737472696e672f6c6963656e7365)](https://github.com/uuf6429/expression-language-tplstring/blob/main/LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/9d7b88c24cd7eea1c4567c2f8b19362fa054351ae9b2032cb49bd6e4791f4339/68747470733a2f2f706f7365722e707567782e6f72672f757566363432392f65787072657373696f6e2d6c616e67756167652d74706c737472696e672f76657273696f6e)](https://packagist.org/packages/uuf6429/expression-language-tplstring)[![Latest Unstable Version](https://camo.githubusercontent.com/d13728a19755d2fdec202125c28c1ea5bcaafa933637b5510e1a99586cf6dd38/68747470733a2f2f706f7365722e707567782e6f72672f757566363432392f65787072657373696f6e2d6c616e67756167652d74706c737472696e672f762f756e737461626c65)](https://packagist.org/packages/uuf6429/expression-language-tplstring)

> **What looks like a dot, a cross and a wave, and does the same thing?**
>
> It's the string concatenation operator, of course!
>
> PHP uses a dot/period (`.`), many languages including JavaScript use `+`, whereas [Symfony Expression Language](https://github.com/symfony/expression-language) uses [the tilde (`~`)](https://symfony.com/doc/current/reference/formats/expression_language.html#string-operators).

This library provides a translation layer on top of Expression Language that converts template strings in [ES6 format\*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#syntax)to a valid expression. While an updated Expression Language subclass wrapper is provided for convenience, you don't have to use it – you can use the provided trait instead.

*\* only ES6 string interpolation (with any expressions and nesting) is supported; f.e. **tagged templates are not**.*

🔌 Installation
--------------

[](#-installation)

As always, the recommended and easiest way to install this library is through [Composer](https://getcomposer.org/):

```
composer require "uuf6429/expression-language-tplstring"
```

🚀 Usage
-------

[](#-usage)

If you do not plan on extending Symfony Expression Language class, you can use the provided drop-in:

```
$el = new \uuf6429\ExpressionLanguage\ExpressionLanguageWithTplStr();
$result = $el->evaluate('`hello ${name}!`', ['name' => 'mars']);
assert($result === 'hello mars!');
```

Otherwise, you can also `use` the provided trait:

```
use uuf6429\ExpressionLanguage\TemplateStringTranslatorTrait;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage as SymfonyExpressionLanguage;
use Symfony\Component\ExpressionLanguage\ParsedExpression as SymfonyParsedExpression;

class MyCustomExpressionLanguage
{
    use TemplateStringTranslatorTrait;

    private SymfonyExpressionLanguage $base;

    public function __construct()
    {
        $this->base = new SymfonyExpressionLanguage();
    }

    public function compile($expression, array $names = []): string
    {
        return $this->base->compile($this->processTemplateStrings($expression), $names);
    }

    public function evaluate($expression, array $values = [])
    {
        return $this->base->evaluate($this->processTemplateStrings($expression), $values);
    }
}

$el = new MyCustomExpressionLanguage();
$result = $el->evaluate('`hello ${name}!`', ['name' => 'world']);
assert($result === 'hello world!');
```

### 🪆 Nested Template Strings

[](#-nested-template-strings)

Since the translator uses a robust state machine, you can nest template strings infinitely:

```
$el = new \uuf6429\ExpressionLanguage\ExpressionLanguageWithTplStr();
$result = $el->evaluate(
    '`Hello ${user.isMember ? `VIP ${user.name}` : \'Guest\'}!`',
    [
        'user' => (object)[
            'isMember' => true,
            'name' => 'John',
        ],
    ]
);
assert($result === 'Hello VIP John!');
```

### 🚨 Robust Error Handling

[](#-robust-error-handling)

Unmatched template boundaries (like unclosed backticks ` `, or unclosed `${`, or unclosed quotes `'`/`"`) will immediately trigger a `Symfony\Component\ExpressionLanguage\SyntaxError` with precise details and position:

```
$el = new \uuf6429\ExpressionLanguage\ExpressionLanguageWithTplStr();
try {
    $el->evaluate('`hello ${name');
} catch (\Symfony\Component\ExpressionLanguage\SyntaxError $e) {
    assert($e->getMessage() === 'Expected "}" around position 13 for expression ``hello ${name`.');
}
```

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance91

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

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

Total

3

Last Release

42d ago

Major Versions

1.0.0 → 2.0.02022-12-24

PHP version history (2 changes)1.0.0PHP ^7 || ^8

2.1.0PHP ^7.4 || ^8

### Community

Maintainers

![](https://www.gravatar.com/avatar/450767af6ef832ad662c169bf718d6d25c025c08b2d91b810959d190bccebba1?d=identicon)[uuf6429](/maintainers/uuf6429)

---

Top Contributors

[![uuf6429](https://avatars.githubusercontent.com/u/230049?v=4)](https://github.com/uuf6429 "uuf6429 (7 commits)")

---

Tags

expression-languagephpsymfonysyntaxtemplate-stringsuuf6429symfonystringparsertemplateexpressionDSLexpression-language

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/uuf6429-expression-language-tplstring/health.svg)

```
[![Health](https://phpackages.com/badges/uuf6429-expression-language-tplstring/health.svg)](https://phpackages.com/packages/uuf6429-expression-language-tplstring)
```

###  Alternatives

[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

12017.1k](/packages/rcsofttech-audit-trail-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M235](/packages/sulu-sulu)

PHPackages © 2026

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