# Twig

[Twig](https://twig.symfony.com/doc/2.x/) is how the story of Melody began. We initially started by writing a parser and compiler for Twig. The last step in the process of creating Melody was deciding on what output it should produce and how its component API should look like.

## About Twig

Twig is a famous templating language for PHP. It was initially introduced as the default templating language in the Symfony PHP framework.

When compared to Handlebars and other popular templating languages, Twig is quite a bit more powerful. It features template inheritance, blocks, embeds, includes, macros, filters and many other things. Additionally, it has been written to support powerful plugins.

## At a glance

### Using variables

Embedding a variable into a template is similar to other template languages. The `{{` and `}}` are enclosing an expression which can be used to include a value into a template.

```markup
<strong>{{ message }}</strong>
```

### Using blocks

A more powerful feature is blocks. Twig supports many different blocks for all intends and purposes.

```markup
{% if isActiveUser %}
<strong>{{ user.name }}</strong>
{% else %}
<a href="/login">Log In</a>
{% endif %}
```

## Learn more

The Twig project offers a very good documentation to the template language which we don't want to duplicate here at the moment. Please take a look at their [documentation](https://twig.symfony.com/doc/2.x/) instead.

Melody behaves identical to Twig in almost all cases unless there are technical limitations preventing us from reaching compatibility. If you notice a difference please report it as a [bug](https://github.com/trivago/melody/issues).
