---
title: "Introduction"
description: "Twig environment for PHP without a framework, with translation, Markdown and route extensions, registration of Symfony UX Twig Components and lint tools for templates"
type: "docs"
category: "doc"
tags: []
authors: [Anonymous]
date: "2026-10-21"
last_update: "2026-10-21"
time_minutes: 2
draft: false
unlisted: false
url: "https://www.derafu.dev/docs/ui/twig/introduction"
---

# Twig Environment, Extensions and Lint Tools for PHP

[![GitHub](https://img.shields.io/badge/github-derafu%2Ftwig-blue?logo=github)](https://github.com/derafu/twig)
![GitHub last commit](https://img.shields.io/github/last-commit/derafu/twig/main)
![CI Workflow](https://github.com/derafu/twig/actions/workflows/ci.yml/badge.svg?branch=main&event=push)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/derafu/twig)
![GitHub Issues](https://img.shields.io/github/issues-raw/derafu/twig)
![Total Downloads](https://poser.pugx.org/derafu/twig/downloads)
![Monthly Downloads](https://poser.pugx.org/derafu/twig/d/monthly)

**Derafu Twig** creates a Twig environment that is ready to use in any PHP code, with or without a framework, and gives it the extensions and the tools that the Derafu libraries use.

## Features

- 🌿 **A Twig environment in one call**: `TwigService` and `TwigCreator` create it from its paths, extensions and components.
- 🧩 **Symfony UX Twig Components without Symfony**: the components of your application (or of a library such as [`derafu/twig-components`](https://www.derafu.dev/docs/ui/twig-components)) are registered in the environment (see [Components](components)).
- 🌐 **Translation**: the `trans` filter, the `t()` function and the tags {% verbatim %}`{% trans %}`{% endverbatim %} and {% verbatim %}`{% trans_default_domain %}`{% endverbatim %}, without `symfony/twig-bridge` (see [Translations](translations)).
- 📝 **Markdown, routes and nested Twig**: the filters `markdown` and `twig` and the functions `path()`, `url()` and `is_active_path()` (see [Extensions](extensions)).
- 🔎 **Lint tools**: they read the templates to find the routes that do not exist and the texts that are not translated (see [Lint](lint)).
- 🗄️ **PSR-6 cache**: the configuration of the components is cached in any PSR-6 pool.
- 🏷️ **MIT License**: open-source and free to use.

## Installation

```bash
composer require derafu/twig
```

## Basic Usage

```php
use Derafu\Twig\Service\TwigService;

$twig = new TwigService([
    'paths' => [__DIR__ . '/templates'],
]);

$data = ['name' => 'World'];

echo $twig->render('hello', $data);                      // Renders templates/hello.html.twig.
echo $twig->renderFromString('Hello {% verbatim %}{{ name }}{% endverbatim %}', $data);   // Renders a string.
```

The service, its options and its defaults are in [Twig Service](service).

## Where to Go Next

- [Twig Service](service): create the environment and render with it.
- [Components](components): register Symfony UX Twig Components.
- [Extensions](extensions): the filters and the functions of the templates.
- [Translations](translations): translate the templates.
- [Lint](lint): check the templates in the tests.



---
Last updated on 21/10/2026

