PHPackages                             phpnomad/twig-integration - 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. phpnomad/twig-integration

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

phpnomad/twig-integration
=========================

1.0.1(1y ago)043[1 PRs](https://github.com/phpnomad/twig-integration/pulls)1MITPHPCI failing

Since Dec 18Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/phpnomad/twig-integration)[ Packagist](https://packagist.org/packages/phpnomad/twig-integration)[ Docs](https://github.com/phoenix/core)[ RSS](/packages/phpnomad-twig-integration/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (3)Versions (5)Used By (1)

phpnomad/twig-integration
=========================

[](#phpnomadtwig-integration)

[![Latest Version](https://camo.githubusercontent.com/2420b1d576cfe1a3452913d6c7dc229cf061ffc424d58e87ce40fd59dcbb012a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068706e6f6d61642f747769672d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/twig-integration)[![Total Downloads](https://camo.githubusercontent.com/c7b88b3b96bbdc69d1e50f04954d19ac206fa4adcb93da54e909398137b95c52/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068706e6f6d61642f747769672d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/twig-integration)[![PHP Version](https://camo.githubusercontent.com/12d3efd51f1c1a5825aac22dd901a30c26a8736d515f7cf15b7d2a5cbea2fe66/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7068706e6f6d61642f747769672d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/twig-integration)[![License](https://camo.githubusercontent.com/386008c4792883555e138accab9ad1a34507bb54e52506cb2d0d7d3c2d4dbb25/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068706e6f6d61642f747769672d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/twig-integration)

Integrates [Twig](https://twig.symfony.com/) with PHPNomad's template strategy. It implements `phpnomad/template`'s `CanRender` interface on top of Twig 3, so any code in your application that depends on `CanRender` can render `.twig` files without knowing Twig is doing the work. This is the default templating integration for PHPNomad applications that run outside WordPress.

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

[](#installation)

```
composer require phpnomad/twig-integration
```

What this provides
------------------

[](#what-this-provides)

- `TwigEngine`, a `CanRender` implementation that loads templates through Twig's `Environment` and `FilesystemLoader` and auto-appends `.twig` to the template path you pass in.
- `TwigConfigProvider`, an interface your application implements to tell the engine where its template directory lives.
- Exception mapping so a missing template surfaces as `TemplateNotFound` and any other render failure surfaces as `TemplateException`, both from `phpnomad/template`.

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

[](#requirements)

- PHP 8.0 or later (inherited from `twig/twig ^3.0`)
- `phpnomad/template ^1.0`
- `twig/twig ^3.0`

Usage
-----

[](#usage)

Implement `TwigConfigProvider` to point at your templates directory, then bind `TwigEngine` to `CanRender` in your bootstrapper's class definitions.

```
