Skip to content

Dynamic Routing in Symfony

The Storyblok Symfony bundle automatically handles dynamic routing based on the slugs and content types defined in Storyblok.

The bundle creates a catch-all route that matches any URL pattern and attempts to resolve it. No need to manually specify routes for each individual story.

When you register a content type controller with the #[AsContentTypeController] attribute, the bundle automatically:

  1. Creates a route that matches the content type.
  2. Fetches the story from Storyblok based on the URL slug.
  3. Instantiates the content type class with the story data.
  4. Calls the controller with the content type instance.

The bundle provides a fallback for unavailable content.

config/packages/storyblok.yaml
base_uri: '%env(STORYBLOK_API_BASE_URI)%'
token: '%env(STORYBLOK_API_TOKEN)%'
version: '%env(STORYBLOK_VERSION)%'
controller:
ascending_redirect_fallback: true

Enable the feature. Now, if a user visits a page that doesn't exist, the bundle automatically redirectd them to its closest parent route.

Was this page helpful?

What went wrong?

This site uses reCAPTCHA and Google's Privacy Policy. Terms of Service apply.