Get node from url | Drupal 8

Get node from url

Submitted by editor on Wed, 12/02/2015 - 14:02

How to get the node or node ID (nid) from url ?


$node = \Drupal::routeMatch()->getParameter('node');
if ($node) {
  $nid = $node->id();

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.