# Templates

> For the complete documentation index, see [llms.txt](https://doc.ibexa.co/en/5.0/llms.txt).

Ibexa DXP uses the Twig template engine to customize the rendering of content in the site.

You can customize the layout and look of your website with templates. Templates use the Twig template engine.

> **Tip: Tip**
>
> Learn more about Twig templates from [Twig documentation](https://twig.symfony.com/doc/3.x/templates.html).

## Connecting templates

Templates can inherit from other templates. Use this, for example, to inherit a general page layout including a [navigation menu](https://doc.ibexa.co/en/5.0/templating/layout/add_navigation_menu/index.md) in article templates.

To inherit from other templates, a template must extend the parent templates by using the [`extends()`](https://twig.symfony.com/doc/3.x/tags/extends.html) Twig function. To extend a parent template, the child template must contain Twig blocks. These blocks are inserted in the parent template in relevant places.

For example, to extend the [general layout of the page](https://doc.ibexa.co/en/5.0/templating/templates/template_configuration/#view-rules-and-matching), which includes, for example, header, footer, or navigation, in the child template place the content in a `content` block:

```html+twig
{% extends '@ibexadesign/pagelayout.html.twig' %}

{% block content %}
{% endblock %}
```

The parent template (in this case, `pagelayout.html.twig`) must leave a place for this block:

```html+twig
{% block content %}
{% endblock %}
```

## Template variables

In templates, you can use variables related to the current content item, and general variables related to the current view and general application settings.

> **Tip: Tip**
>
> For development purposes, you can list all available variables, or a single variable, and their values, by using the `dump()` Twig function:
>
> ```html+twig
> {{ dump() }}
> {{ dump(content) }}
> ```

Main variables include:

| Variable                      | Description                                                                                                                                              |
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `content`                     | Content item, containing all Fields and version information (VersionInfo).                                                                               |
| `location`                    | Location object. Contains meta information on the Content (ContentInfo).                                                                                 |
| `ibexa.siteaccess`            | Current [SiteAccess](https://doc.ibexa.co/en/5.0/multisite/multisite/index.md).                                                                          |
| `ibexa.rootLocation`          | Root Location object.                                                                                                                                    |
| `ibexa.requestedUriString`    | Requested URI string.                                                                                                                                    |
| `ibexa.systemUriString`       | System URI string. System URI is the URI for internal content controller. If the current route isn't a URL alias, then the current PathInfo is returned. |
| `ibexa.viewParameters`        | View parameters as a hash.                                                                                                                               |
| `ibexa.viewParametersString`  | View parameters as a string.                                                                                                                             |
| `ibexa.translationSiteAccess` | Translation SiteAccess for a given language (null if the SiteAccess cannot be found).                                                                    |
| `ibexa.availableLanguages`    | List of available languages.                                                                                                                             |
| `ibexa.configResolver`        | [Config resolver](https://doc.ibexa.co/en/5.0/administration/configuration/dynamic_configuration/#configresolver).                                       |

### Custom template variables

You can create custom Twig variables for use in templates. Set the variables per SiteAccess or SiteAccess group ([scope](https://doc.ibexa.co/en/5.0/multisite/multisite_configuration/#scope)), or per content view.

To configure a custom template variable per scope, use the `twig_variables` [configuration key](https://doc.ibexa.co/en/5.0/administration/configuration/configuration/#configuration-files):

```yaml
ibexa:
    system:
        site_group:
            twig_variables:
                custom_variable: 'variable_value'
```

You can access this variable directly in all templates in that scope:

```html+twig
{{ custom_variable }}
```

Variables set for a specific content view (under `params`) are only available when this view is matched:

```yaml
                line:
                    article:
                        template: '@ibexadesign/line/article.html.twig'
                        match:
                            Identifier\ContentType: [article]
                        params:
                            custom_variable_per_view: 'variable_value'
```

Custom variables can be nested:

```yaml
twig_variables:
    custom_variable:
        nested_variable: 'variable_value'
```

```html+twig
{{ custom_variable.nested_variable }}
```

You can use [Symfony Expression language](https://symfony.com/doc/7.4/expression_language.html) to access other values, for example:

```yaml
params:
    custom_variable: "@=content.contentType.identifier"
```

> **Note: Note**
>
> A custom variable can overwrite an existing variable, so it's good practice to avoid existing variable names such as `content` or `location`.
