> For the complete documentation index, see [llms.txt](https://metabolism.gitbook.io/symfony-wordpress-bundle/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://metabolism.gitbook.io/symfony-wordpress-bundle/reference/controller/blogcontroller.md).

# BlogController

### Rendering Templates <a href="#rendering-templates" id="rendering-templates"></a>

If you're serving HTML, you'll want to render a template. The `render()` method renders a template **and** puts that content into a `Response` object for you:

```php
return $this->render('home.html.twig', ['post'=>$post]);
```

Templating and Twig are explained more in the [Creating and Using Templates article](https://symfony.com/doc/current/templates.html).

### Fetching Services

Symfony comes *packed* with a lot of useful classes and functionalities, called [services](https://symfony.com/doc/current/service_container.html). These are used for rendering templates, sending emails, querying the database and any other "work" you can think of.

If you need a service in a controller, type-hint an argument with its class (or interface) name. Symfony will automatically pass you the service you need:

```php
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Response;

public function homeAction(Post $post, LoggerInterface $logger)
{
    $logger->info('We are logging!');
    // ...
}
```

The Wordpress Bundle adds two services : [PaginationService](/symfony-wordpress-bundle/reference/service/paginationservice.md) and [BreadcrumbService](/symfony-wordpress-bundle/reference/service/breacrumbservice.md)

```php
/**
 * @param PostCollection $posts
 * @params PostRepository $postRepository
 * @param PaginationService $paginationService
 * @param BreadcrumbService $breadcrumbService
 * @return Response
 */
public function articleThematicAction(PostCollection $posts, PostRepository $postRepository, PaginationService $paginationService, BreadcrumbService $breadcrumbService)
{
    $context = ['posts'=>$posts];

    if( $page = $postRepository->findByState('news_landing') ){

        $context['breadcrumb'] = $breadcrumbService->build(['data'=>[[
            'title'=> $page->getTitle(),
            'link'=> $page->getLink()
        ]]]);
    }

    $context['pagination'] = $paginationService->build();

    return $this->render('page/term.twig', $context);
}
```

{% hint style="info" %}
`get_page_by_state` is a new function available in the WP Steroids plugin, see [docs](/symfony-wordpress-bundle/guides/wp-steroids-plugin/page-states.md)&#x20;
{% endhint %}

### Fetching Repository

The Wordpress Bundle adds three repository : [PostRepository](/symfony-wordpress-bundle/reference/repository/postrepository.md), [TermRepository](/symfony-wordpress-bundle/reference/repository/termrepository.md) and [UserRepository](/symfony-wordpress-bundle/reference/repository/userrepository.md) designed to mimic [Doctrine Repository](https://symfony.com/doc/current/doctrine.html#fetching-objects-from-the-database) way to fetch object from database.&#x20;

Internally, it still uses Wordpress native functions WP\_Query, WP\_Term\_Query and WP\_User\_Query to ensure plugins compatibility

```php
/**
 * @param Post $post
 * @param PostRepository $postRepository
 * @return Response
 */
public function pageAction(Post $post, PostRepository $postRepository)
{
    $context = [
        'post' => $post,
        'related' => $postRepository->findBy(['post_type'=>'page', 'post_parent' => $post->parent, 'post__not_in' => [$post->ID] ],null, 4)
    ];

     return $this->render('page.html.twig', $context);
}
```
