src/Controller/TemplateCustomController.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\Template\TemplatePageRepository;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. class TemplateCustomController extends AbstractController
  8. {
  9. /**
  10. * @var TemplatePageRepository
  11. */
  12. private $repo;
  13. /**
  14. * @param TemplatePageRepository $repo
  15. */
  16. public function __construct(TemplatePageRepository $repo)
  17. {
  18. $this->repo = $repo;
  19. }
  20. /**
  21. * @param string $slug
  22. * @return Response
  23. */
  24. #[Route(path: '/{slug}', name: 'template_custom')]
  25. public function __invoke(string $slug)
  26. {
  27. if (null === $currentPage = $this->repo->findOneBySlug($slug)) {
  28. throw $this->createNotFoundException(sprintf('Cannot found template for slug "%s".', $slug));
  29. }
  30. return $this->render('Front/template_custom/index.html.twig', [
  31. 'current_page' => $currentPage
  32. ]);
  33. }
  34. }