Load A Node Via URL Alias
Snippet of code that will load a node object using the URL alias path and get the content type.
/** @var Drupal\Core\Url $url */ $url = $variables['url']; if ($url instanceof Drupal\Core\Url) { $nid = $url->getRouteParameters()['node']; /** @var \Drupal\node\Entity\Node $node */ $node = Node::load($nid); if ($node instanceof Node) { $type = $node->getType(); } }
The Github Gist: Load A Node Using URL Alias