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:
- Creates a route that matches the content type.
- Fetches the story from Storyblok based on the URL slug.
- Instantiates your content type class with the story data.
- Calls your controller with the content type instance.
Fallback Behavior
The bundle provides a fallback feature for content that’s not available.
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.
Next Part
Content Modeling with StoryblokPrevious Part
Visual Preview in Storyblok