My route is
admin:
path: /admin/
defaults: { _controller: CatalogWebBundle:Admin:admin }
How I can get route name in PHP template ?
To get the Route Name in Symfony2 enter the following code snippet
$request = $this->container->get('request');
$routeName = $request->get('_route');
To get the URL in Symfony2,
$request = $this->container->get('request');
$routeURL = $request->getRequestUri();
On symfony5 you can do this.
Calling a controller block and passing current url:
{{ render_esi(controller('App\\Controller\\Frontend\\BlockController::social',{'pageUri': app.request.uri })) }}
and
<?php
namespace App\Controller\Frontend;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class BlockController extends AbstractController {
public function social($pageUri) {
return $this->render('block/_social.html.twig', ['pageUri' => $pageUri]);
}
}
Output twig: 'block/_social.html.twig'
<small>Current Url : {{ pageUri }}</small>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With