# Twig

> The flexible, fast, and secure template engine for PHP

Source: https://talira.ai/catalog/twig-gty3db20
Every listing: https://talira.ai/catalog.md

- Kind: Open source
- Types: Library
- Categories: [libraries / templating](https://talira.ai/categories/libraries/templating), [languages / php](https://talira.ai/categories/languages/php)
- Licence: BSD-3-Clause[^2]
- Pricing: Free and open source[^2]
- Free tier: yes[^2]
- Backed by: [Twig Team](https://talira.ai/orgs/twig-team.md)

Twig is a template engine for PHP. It compiles templates down to plain optimized PHP, escapes output with a short syntax (`{{ var|e }}`), supports multiple inheritance and blocks, and has a sandbox mode for evaluating template code users can edit. Its lexer and parser let developers define their own tags and filters, and even a DSL. Fabien Potencier leads it; Armin Ronacher founded the project.

## Links

- Website: https://twig.symfony.com/
- GitHub: https://github.com/twigphp/Twig
- Docs: https://twig.symfony.com/doc/3.x/

## Problems it solves

- my PHP views are full of echo and htmlspecialchars calls
- let customers edit email or page templates without running arbitrary PHP
- a template language for PHP with layouts and inheritance

## Features

- a template engine for PHP with concise syntax and automatic output escaping
- compiles templates to optimized PHP
- template inheritance, blocks and macros
- sandbox mode for templates users can edit
- custom tags, filters and functions

## Limitations

- Twig 3 needs PHP 8.1 or later.[^1]

## Trust

Overall: 0.70 out of 1.
Signals: maintenance 1.00, adoption 0.78, momentum 0.49, community 1.00, backing 0.30, extensibility 0.00.

- last commit 5 days ago
- 210 commits in the last 90 days
- latest release v4.0.0-beta1 5 days ago
- 8.4k GitHub stars
- 533 contributors
- accepts sponsorship (Github, Tidelift, Custom)
- backed by Twig Team

## Alternatives

- [Latte](https://talira.ai/catalog/latte-k93t7svg.md): PHP template engine with context-sensitive escaping
- [Smarty (PHP)](https://talira.ai/catalog/smarty-php-6ts7hh16.md): The compiling template engine for PHP
- [Jinja](https://talira.ai/catalog/jinja-kvze87j3.md): A very fast and expressive template engine

## Sources

[^1]: https://github.com/twigphp/Twig/blob/3.x/composer.json (checked 26 Nov 2026)
[^2]: https://github.com/twigphp/Twig/blob/3.x/LICENSE (checked 26 Nov 2026)
