---
title: "Derafu"
description: "Derafu"
type: "docs"
category: "doc"
tags: []
authors: [Anonymous]
date: "2026-10-20"
last_update: "2026-10-20"
time_minutes: 2
draft: false
unlisted: false
url: "https://www.derafu.dev/docs/ui/twig-components/derafu"
---

# Derafu

[`derafu/twig`](https://www.derafu.dev/docs/ui/twig) creates a Twig environment without Symfony and registers Symfony UX Twig Components in it. This is how the components are used in a Derafu site.

```bash
composer require derafu/twig derafu/twig-components
```

`derafu/twig` does not know the components of this package, and this package does not depend on `derafu/twig`: the one that builds the environment is the one that gives them.

## Directly

Give the environment the templates of the package in `paths`, and the components in `components`. The directory of the classes has all of them:

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

$vendor = __DIR__ . '/vendor/derafu/twig-components';

$twig = new TwigService([
    'paths' => [__DIR__ . '/templates', $vendor . '/resources/templates'],
    'components' => new DirectoryComponentProvider($vendor . '/src/Component'),
]);

$data = [];

echo $twig->renderFromString('<twig:block-alert type="info" content="Hello" />', $data);
```

The `components` option also takes the classes of the components, or their instances (see [Components](https://www.derafu.dev/docs/ui/twig/components)).

## With the Container

The file `resources/config/twig-components-services.yaml` registers every component with the tag `derafu_twig.component`, and the translations of the package with the tag `derafu_translation.resource_provider`. Import it in your services:

```yaml
imports:
    - { resource: '../vendor/derafu/twig-components/resources/config/twig-components-services.yaml' }
```

The `components` option of `derafu/twig` takes that iterable (see [Components](https://www.derafu.dev/docs/ui/twig/components#with-the-container)), so the creator of the environment gives it with:

```yaml
components: !tagged_iterator derafu_twig.component
```

## With the Renderer

[`derafu/renderer`](https://www.derafu.dev/docs/ui/renderer) gives its `components` option to its Twig environment:

```php
use Derafu\Renderer\Factory\RendererFactory;
use Derafu\Twig\Provider\DirectoryComponentProvider;

$vendor = __DIR__ . '/vendor/derafu/twig-components';

$renderer = RendererFactory::create([
    'paths' => [__DIR__ . '/templates', $vendor . '/resources/templates'],
    'components' => new DirectoryComponentProvider($vendor . '/src/Component'),
]);

echo $renderer->renderFromString('<twig:block-alert type="info" content="Hello" />');
```



---
Last updated on 20/10/2026

