How to get and check current url in the view twig template?


#1

In the main layout of view, I want to put condition to display separately div content in home and another page.


#2

Here is an example.

PHP

public function __invoke(Request $request, Response $response): ResponseInterface
{
    $viewData = [
        'url' => $request->getUri(),
    ];
    
    return $this->view->render($response, 'Home/home-index.twig', $viewData);
}

Twig Template

URL: {{ url }}