---
title: Visual Preview in Symfony
description: Learn how to connect your Symfony project to Storyblok’s Visual Editor for a seamless, intuitive content editing experience.
url: https://storyblok.com/docs/guides/symfony/visual-preview
---

# Visual Preview in Symfony

Connect the local project with Storyblok's Visual Editor to enhance the editorial and development experience.

## Set the default environment

Open **Settings** → **Visual Editor** and set the default environment to the URL of the local development server: `https://localhost:8000/`

> [!NOTE]
> Storyblok's preview environment requires an `https` connection. The Symfony CLI command `symfony server:start` automatically runs a secure local server.

Restart the development server if necessary.

To render the home story at the root, open Home story. In the Visual Editor, select the **Config** section and type `/` in the **Real path** field.

In the code editor, add a home page controller to reroute the `home` slug.

src/Controller/HomepageController.php

```php
<?php

declare(strict_types=1);

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;

final class HomepageController extends AbstractController
{
  #[Route('/', name: 'homepage', priority: 100)]
  public function index(Request $request): RedirectResponse
  {
    return $this->redirectToRoute(\Storyblok\Bundle\Routing\Route::CONTENT_TYPE, ['slug' => 'home']);
  }
}
```

## **Set up Storyblok’s Bridge**

Connect block classes with their Storyblok counterparts via the `EditableInterface` and use the `EditableTrait` modules.

Adapt the `Feature` block and template.

src/Block/Feature.php

```php
<?php

declare(strict_types=1);

namespace App\Block;

use Storyblok\Bundle\Block\Attribute\AsBlock;
use Storyblok\Api\Domain\Type\Editable;
use Storyblok\Bundle\Editable\EditableInterface;
use Storyblok\Bundle\Editable\EditableTrait;

#[AsBlock]
final readonly class Feature implements EditableInterface
{
  use EditableTrait;
  public string $name;

  public function __construct(array $values)
  {
    $this->name = $values['name'] ?? '';
    $editable = null;
    if (\array_key_exists('_editable', $values)) {
      $editable = new Editable($values['_editable']);
    }
    $this->editable = $editable;
  }
}
```

In the template, use the `storyblok_attributes` filter to make content editable in the Visual Editor:

templates/blocks/feature.html.twig

```html
<div class="feature">
<div {{ block|storyblok_attributes }} class="feature">
  <span>{{ block.name }}</span>
</div>
```

Add the Storyblok Bridge script to the base template.

templates/base.html.twig

```html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    {% block stylesheets %}
    {% endblock %}
    {% block javascripts %}
    {% endblock %}
  </head>
  <body>
    <div class="container">
    {% block body %}{% endblock %}
  </div>

    {% block storyblok_scripts %}
      {{ storyblok_js_bridge_scripts() }}
    {% endblock %}
  </body>
</html>
```

  {% block stylesheets %} {% endblock %} {% block javascripts %} {% endblock %}  

 {% block body %}{% endblock %}

 {% block storyblok\_scripts %} {{ storyblok\_js\_bridge\_scripts() }} {% endblock %}
