Skip to content

Instantly share code, notes, and snippets.

@woutersf
Last active December 28, 2016 12:09
Show Gist options
  • Save woutersf/08558c57f4bebe252611ef8a787cfff4 to your computer and use it in GitHub Desktop.
Save woutersf/08558c57f4bebe252611ef8a787cfff4 to your computer and use it in GitHub Desktop.
D8 Match a canonical route
<?php
//If is frontpage
$on_frontpage = \Drupal::service('path.matcher')->isFrontPage();
//Match canonical route
$route_match = \Drupal::routeMatch();
if ($route_match->getRouteName() == 'entity.node.canonical') {
// Do something..
}
// Match alias
$current_path = \Drupal::service('path.current')->getPath();
if($current_path == '/user/login') {
// Do something..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment