# Templates

{% hint style="info" %}
This bundle come without theme, you can start reading the official Symfony [documentation](https://symfony.com/doc/current/templates.html) to create templates.
{% endhint %}

## Twig Templating Language

The [Twig](https://twig.symfony.com/) templating language allows you to write concise, readable templates that are more friendly to web designers and, in several ways, more powerful than PHP templates. Take a look at the following Twig template example. Even if it's the first time you see Twig, you probably understand most of it:

```twig
<!DOCTYPE html>
<html>
    <head>
        <title>{{ blog.title|raw }}</title>
    </head>
    <body>
        <h1>{{ post.title }}</h1>

        {% if blog.user %}
            Hello {{ blog.user.nicename }}!
        {% endif %}

        {# ... #}
    </body>
</html>g
```

You can't run PHP code inside Twig templates, but Twig provides utilities to run some logic in the templates. For example, **filters** modify content before being rendered, like the `upper` filter to uppercase contents:

```twig
{{ post.title|upper }}
```

## Creating Templates

Before explaining in detail how to create and render templates, look at the following example for a quick overview of the whole process. First, you need to create a new file in the `templates/` directory to store the template contents:

```twig
{# templates/home.html.twig #}
<h1>{{ post.title }}!</h1>
<div>{{ post.excerpt|raw }}</div>
```

Then, create a [controller](https://symfony.com/doc/current/controller.html) that renders this template and passes to it the needed variables:

```php
// src/Controller/BlogController.php
<?php

namespace App\Controller;

use Metabolism\WordpressBundle\Entity\Post;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class BlogController extends AbstractController
{
	public function homeAction(Post $post)
	{
		return $this->render('home.html.twig', ['post'=>$post]);
	}
}
```

{% hint style="info" %}
Methods are called automatically if the provided routing is used, see [Router page](/symfony-wordpress-bundle/getting-started/router.md).\
To get action name, just click on Wordpress permalink, an error will display the expected method name :

**`InvalidArgumentException`**`> The controller for URI "/" is not callable: Expected method "homeAction" on class "App\Controller\BlogController".`
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://metabolism.gitbook.io/symfony-wordpress-bundle/getting-started/templates.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
