PHPackages                             tamdaz/tempest-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. tamdaz/tempest-twig

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

tamdaz/tempest-twig
===================

A third-party package that provides Twig for Tempest.

v0.2.0(1mo ago)09[1 PRs](https://github.com/tamdaz/tempest-twig/pulls)MITPHPPHP ^8.5CI passing

Since Mar 28Pushed 4mo agoCompare

[ Source](https://github.com/tamdaz/tempest-twig)[ Packagist](https://packagist.org/packages/tamdaz/tempest-twig)[ RSS](/packages/tamdaz-tempest-twig/feed)WikiDiscussions main Synced 1w ago

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

tempest-twig
============

[](#tempest-twig)

Tempest Twig is a third-party package that integrates the Twig templating engine with the [Tempest framework](https://tempestphp.com). It provides full Twig `3.x` support, custom extensions for routing and debugging, and an innovative component system using HTML-like syntax.

The package includes flexible configuration for template paths, built-in Twig extensions that work with Tempest's routing and Vite pipeline, and a sophisticated component transformation system.

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

[](#installation)

First, install the Composer package:

```
composer require tamdaz/tempest-twig
```

Configuration
-------------

[](#configuration)

### View configuration

[](#view-configuration)

For the moment, Tempest still renders views with its own default renderer. To render views with Twig, create *(or edit)* your view configuration and set `rendererClass` explicitly via `php tempest make:config view`:

```
+use Tamdaz\TempestTwig\Twig\TwigViewRenderer;
use Tempest\View\ViewConfig;

return new ViewConfig(
+    rendererClass: TwigViewRenderer::class,
);
```

This keeps the renderer choice explicit: installing Tempest Twig never overrides an already configured renderer.

### Twig Options

[](#twig-options)

Twig itself is configured through a file in the `config` directory, automatically discovered and loaded by Tempest.

```
// config/twig.config.php
use Tempest\View\Renderers\TwigConfig;
use function Tempest\env;
use function Tempest\root_path;

return new TwigConfig(
    viewPaths: [
        root_path('templates'),
    ],
    debug: env('APP_DEBUG', false),
    strictVariables: true,
);
```

The `TwigConfig` class wraps Twig's standard options. The `viewPaths` parameter specifies which directories to search for templates, and multiple directories can be added for different template locations. Other options like `debug`, `charset`, `strictVariables`, and `autoescape` follow Twig's standard behavior.

Twig Functions
--------------

[](#twig-functions)

Tempest Twig automatically registers custom Twig functions that integrate with the Tempest framework. These functions are available in all templates without any additional setup.

### Routing Functions

[](#routing-functions)

The `route()` function generates URLs for named routes or controller methods, accepting route parameters directly:

```
{{ route('route.name') }}
{{ route(['App\\Controllers\\ControllerClass', 'method']) }}
{{ route(['App\\Controllers\\ControllerClass', 'method'], param1, param2) }}
```

The `signed_route()` function generates URLs with cryptographic signatures, while `temporary_signed_route()` produces links that expire after a duration (in seconds):

```
{{ signed_route('route.name') }}
{{ temporary_signed_route('route.name', 3600) }}
```

The `is_current_route()` function checks the current route, useful for highlighting active navigation items:

```
{% if is_current_route('route.name') %}
  Active
{% endif %}
```

The `current_path()` function returns the current request path as a string.

### Vite Functions

[](#vite-functions)

For Tempest applications using Vite for asset bundling, the package provides integration functions. The `vite_tags()` function generates script and link tags for Vite entry points:

```
{{ vite_tags('resources/js/app.ts', 'resources/css/app.css') }}
```

The `vite_asset()` function returns the public URL of an asset from Vite's manifest:

```

```

### Debug Functions

[](#debug-functions)

Tempest Twig includes debugging and utility functions. The `dump()` function inspects variables during development. The `class()` function returns an object's class name, and `is_empty()` checks if a variable is empty:

```
{{ dump(user, post) }}
{{ class(user) }}
{% if is_empty(posts) %}No posts{% endif %}
```

Additional utilities include `get_type()` for variable types, `env()` for environment variables with fallback, `root_path()` for absolute paths scoped to the project root, and `to_json()` for converting PHP values to JSON:

```
{{ get_type(value) }}
{{ env('APP_NAME', 'MyApp') }}
{{ root_path('storage', 'app.log') }}

  const data = {{ to_json(users) }};

```

The `count()` function counts array elements, `current_url()` gives the full URL, and `now()` provides the current timestamp.

Component System
----------------

[](#component-system)

Tempest Twig includes a component system using HTML-like syntax. Instead of writing Twig `include` and `embed` directives, component tags that look like HTML custom elements can be written directly. The package transforms these tags into native Twig directives automatically.

### Self-Closing Components

[](#self-closing-components)

Self-closing components are ideal for simple UI elements like buttons and badges, written as XML-style tags with attributes:

```

```

This transforms into a Twig `include` directive that passes attributes as variables:

```
{% include 'components/Button.html.twig' with { label: 'Click me', variant: 'primary' } only %}
```

The component template at `templates/components/Button.html.twig`:

```

  {{ label }}

```

### Components with Content

[](#components-with-content)

Components can wrap content, similar to Vue or React components. Content added between tags transforms into an `embed` directive:

```

  This is a warning message

```

This becomes:

```
{% embed 'components/Alert.html.twig' with { type: 'warning' } %}
  {% block content %}This is a warning message{% endblock %}
{% endembed %}
```

The component template accesses the content through Twig's block system:

```

  {% block content %}{% endblock %}

```

### Components with Named Slots

[](#components-with-named-slots)

Complex components can define named content areas using `` tags, allowing different parts to accept different content:

```

    {{ title }}

  Card content goes here

```

The component template can define multiple named blocks:

```

  {% if block('header') is not empty %}

      {% block header %}{% endblock %}

  {% endif %}

    {% block content %}{% endblock %}

```

Default content (anything not in ``) goes into the `content` block. Named blocks are optional, and checking whether they have content before rendering avoids empty markup.

### Attribute Binding

[](#attribute-binding)

Components accept both static attributes and dynamic Twig expressions. Static attributes are quoted strings, while dynamic attributes use a colon prefix:

```

```

All attributes are available as variables inside the component. The preprocessor handles nested components and escapes attribute values properly.

Testing and Development
-----------------------

[](#testing-and-development)

The package includes a test suite covering component attribute parsing, template transformation, and loader functionality. Run tests with:

```
composer test
```

All tests use PHPUnit and follow the standard test directory structure. The package includes GitHub Actions workflows for continuous integration and compatibility checks.

License
-------

[](#license)

This package is licensed under the MIT license. See `LICENSE` for details.

Support and Contributing
------------------------

[](#support-and-contributing)

If you encounter any issues or have suggestions for improvements, you can open an issue or a PR on GitHub. Contributions are welcome!

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance83

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

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

Total

2

Last Release

38d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/120991635?v=4)[Zohir Tamda](/maintainers/tamdaz)[@tamdaz](https://github.com/tamdaz)

---

Top Contributors

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

---

Tags

tempestthird-partytwig

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tamdaz-tempest-twig/health.svg)

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.7M3.4k](/packages/craftcms-cms)[symfony/ux-live-component

Live components for Symfony

1657.5M147](/packages/symfony-ux-live-component)

PHPackages © 2026

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