Dynamic Routing in Symfony
The Storyblok Symfony bundle automatically handles dynamic routing based on the slugs and content types defined in Storyblok.
Fetch a story dynamically
Section titled “Fetch a story dynamically”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:
- Creates a route that matches the content type.
- Fetches the story from Storyblok based on the URL slug.
- Instantiates the content type class with the story data.
- Calls the controller with the content type instance.
Fallback behavior
Section titled “Fallback behavior”The bundle provides a fallback for unavailable content.
base_uri: '%env(STORYBLOK_API_BASE_URI)%'token: '%env(STORYBLOK_API_TOKEN)%'version: '%env(STORYBLOK_VERSION)%'controller: ascending_redirect_fallback: trueEnable the feature. Now, if a user visits a page that doesn't exist, the bundle automatically redirectd them to its closest parent route.
Related resources
Section titled “Related resources”Was this page helpful?
This site uses reCAPTCHA and Google's Privacy Policy. Terms of Service apply.
Get in touch with the Storyblok community