Keep HTML layout files separate from PHP business logic in any PHP project or Symfony app.
Safely render user-submitted templates without letting them execute arbitrary PHP code, using Twig's sandbox mode.
Define a reusable base page layout with header and footer, then override only the content block in each page template.
Transform and format data inline in templates using Twig filters, without touching PHP controller code.
Twig is a template language for PHP. PHP is a programming language commonly used to build websites, and Twig lets developers keep the HTML structure of their pages separate from the PHP code that generates the data. Instead of mixing PHP logic directly into HTML files, you write templates in Twig's own syntax, which is cleaner and easier to read. The syntax was inspired by Django and Jinja, which are template languages used in the Python world. Developers familiar with those will find Twig's style familiar. It uses double curly braces to output variables, blocks for defining sections that child templates can override, and filters for transforming data inline. Twig is most commonly encountered as the default templating layer in Symfony, a widely used PHP web framework, but it can be used independently in any PHP project. It is designed with three goals: flexibility (it can be extended with custom tags and filters), performance (templates are compiled to PHP classes and cached), and security (it sandboxes untrusted template code so that user-supplied templates cannot execute arbitrary PHP). The README for this repository is minimal and points readers to the official documentation website for setup and usage details. The project is mature and widely adopted in the PHP ecosystem, with a long maintenance history.
← twigphp on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.