Storyblok
Search Storyblok's Documentation
  1. Dynamic Routing in Symfony

Dynamic Routing in Symfony

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

Fetch a story dynamically

The Storyblok Symfony bundle automatically creates a catch-all route that matches any URL pattern and attempts to resolve it. This means you don't need to manually define routes for each piece of content.

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 your content type class with the story data.
  4. Calls your controller with the content type instance.

Fallback Behavior

The bundle provides a fallback feature for content that’s not available.

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

When enabled, if a user visits a route that doesn't exist, the bundle will automatically redirect to its closest existing parent route.