@@ -230,7 +230,7 @@ Consider the following routing configuration:
230230 <routes xmlns =" http://symfony.com/schema/routing"
231231 xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
232232 xsi : schemaLocation =" http://symfony.com/schema/routing
233- https://symfony.com/schema/routing/routing-1.0.xsd" >
233+ https://symfony.com/schema/routing/framework- routing-1.0.xsd" >
234234
235235 <route id =" blog_index"
236236 path =" /"
@@ -245,7 +245,7 @@ Consider the following routing configuration:
245245
246246 // config/routes.php
247247 use App\Controller\BlogController;
248- use Symfony\Component \Routing\Loader\Configurator\RoutingConfigurator;
248+ use Symfony\Bundle\FrameworkBundle \Routing\Loader\Configurator\RoutingConfigurator;
249249
250250 return function (RoutingConfigurator $routes) {
251251 $routes->add('blog_index', '/')
@@ -457,8 +457,8 @@ Rendering a Template Directly from a Route
457457~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
458458
459459Although templates are usually rendered in controllers and services, you can
460- render static pages that don't need any variables directly from the route
461- definition. Use the special :class: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ TemplateController `
460+ render static pages from the route definition. Use the special
461+ :class: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ TemplateController `
462462provided by Symfony:
463463
464464.. configuration-block ::
@@ -468,81 +468,77 @@ provided by Symfony:
468468 # config/routes.yaml
469469 acme_privacy :
470470 path : /privacy
471- controller : Symfony\Bundle\FrameworkBundle\Controller\TemplateController
472- defaults :
473- # the path of the template to render
474- template : ' static/privacy.html.twig'
471+ # the path of the template to render
472+ template : ' static/privacy.html.twig'
475473
476- # special options defined by Symfony to set the page cache
477- maxAge : 86400
478- sharedAge : 86400
474+ # special options defined by Symfony to set the page cache
475+ maxAge : 86400
476+ sharedAge : 86400
479477
480- # whether or not caching should apply for client caches only
481- private : true
478+ # whether or not caching should apply for client caches only
479+ private : true
482480
483- # optionally you can define some arguments passed to the template
484- context :
485- site_name : ' ACME'
486- theme : ' dark'
481+ # some variables passed to the template
482+ context :
483+ site_name : ' ACME'
484+ theme : ' dark'
487485
488486 .. code-block :: xml
489487
490488 <!-- config/routes.xml -->
491489 <?xml version =" 1.0" encoding =" UTF-8" ?>
492490 <routes xmlns =" http://symfony.com/schema/routing"
493491 xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
494- xsi : schemaLocation =" http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd" >
492+ xsi : schemaLocation =" http://symfony.com/schema/routing
493+ https://symfony.com/schema/routing/framework-routing-1.0.xsd" >
495494
496- <route id =" acme_privacy"
495+ <template- route id =" acme_privacy"
497496 path =" /privacy"
498- controller =" Symfony\Bundle\FrameworkBundle\Controller\TemplateController" >
499497 <!-- the path of the template to render -->
500- < default key = " template " > static/privacy.html.twig</ default >
498+ template=" static/privacy.html.twig"
501499
502500 <!-- special options defined by Symfony to set the page cache -->
503- < default key = " maxAge " > 86400</ default >
504- < default key = " sharedAge " > 86400</ default >
501+ maxAge=" 86400"
502+ sharedMaxAge=" 86400" >
505503
506504 <!-- whether or not caching should apply for client caches only -->
507505 <default key =" private" >true</default >
508506
509- <!-- optionally you can define some arguments passed to the template -->
510- <default key = " context" >
511- <default key =" site_name" >ACME</default >
512- <default key =" theme" >dark</default >
513- </default >
514- </route >
507+ <!-- some variables passed to the template -->
508+ <context >
509+ <string key =" site_name" >ACME</string >
510+ <string key =" theme" >dark</string >
511+ </context >
512+ </template- route >
515513 </routes >
516514
517515 .. code-block :: php
518516
519517 // config/routes.php
520- use Symfony\Bundle\FrameworkBundle\Controller\TemplateController;
521- use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
518+ use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
522519
523520 return function (RoutingConfigurator $routes) {
524521 $routes->add('acme_privacy', '/privacy')
525- ->controller(TemplateController::class)
526- ->defaults([
527- // the path of the template to render
528- 'template' => 'static/privacy.html.twig',
529-
530- // special options defined by Symfony to set the page cache
531- 'maxAge' => 86400,
532- 'sharedAge' => 86400,
533-
534- // whether or not caching should apply for client caches only
535- 'private' => true,
536-
537- // optionally you can define some arguments passed to the template
538- 'context' => [
539- 'site_name' => 'ACME',
540- 'theme' => 'dark',
541- ]
522+ // the path of the template to render and a context of variables passed to it
523+ ->template('static/privacy.html.twig', [
524+ 'site_name' => 'ACME',
525+ 'theme' => 'dark',
542526 ])
527+
528+ // special options defined by Symfony to set the page cache
529+ ->maxAge(86400)
530+ ->sharedMaxAge(86400)
531+
532+ // whether or not caching should apply for client caches only
533+ ->private()
543534 ;
544535 };
545536
537+ .. versionadded :: 5.1
538+
539+ This short syntax was introduced in Symfony 5.1. Before you had to
540+ define the controller and specific route attributes using ``defaults ``.
541+
546542.. versionadded :: 5.1
547543
548544 The ``context `` option was introduced in Symfony 5.1.
0 commit comments