When updating the app from Symfony 2.8 to Symfony 3.4, the handling of _format
changed, so I would like to change @Template to render as shown in the post below.
However, because twig is changed in Parent format
Unable to specify twig file in return of BaseStaffController.php.
Is there any good way?
How to reference multiple twigs with @Template()
Controller
/** * @Route("/staff/", defaults={"_format"="html"}, requirements={"_format"="html|csv"}) * @Method("GET") * * @Template("@AppBundle/Hq/Analytics/staff.html.twig") */ public function staffAction(Request $request) { return parent::staffAction($request); }
BaseStaffController
/** */ public function staffAction(Request $request) { return array( 'searchForm' => $searchForm->createView(), 'pagination' => $pagination, 'no' => $no ); }
Advertisement
Answer
If parent::staffAction
is just returning the array of variables to be passed to the twig template then you can simply pass it along to the render
method.
/** * @Route("/staff/", defaults={"_format"="html"}, requirements={"_format"="html|csv"}) * @Method("GET") * */ public function staffAction(Request $request) { return $this->render("Hq/Analytics/staff.html.twig", parent::staffAction($request)); }