Reputation: 308
Is it possible to get Title of a page from the url or route name.
I have a router name for example: view.topics_landing_page.page
Or the same page has a path: /topics By using either path or Route name, I wants to get the title Eg:- Topics.
Is it possible?
Thanks in Advance.
Upvotes: 1
Views: 5414
Reputation: 461
The only way to get the page title of any URL/route would be to actually request the page and see what the title is. The reason is that any module or the theme could alter the title from what it normally would be, like fx metatags module.
To get the title of the current page you could do this:
use \Symfony\Cmf\Component\Routing\RouteObjectInterface;
$request = \Drupal::request();
if ($route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT)) {
$title = \Drupal::service('title_resolver')->getTitle($request, $route);
}
But another thing you could do is override the breadcrumb.html.twig template. This will render the template wherever you place the Breadcrumb block.
Upvotes: 2
Reputation: 92
Drupal 8 has core functionality for page title.
In block structure you can see "Page Title" [Link : your-domain/admin/structure/block]
You can use this one on any region you want to show title of current page. Clear you cache after set this block on region..!!
Upvotes: 1