Skip to content

Instantly share code, notes, and snippets.

@mikedotexe
Created June 20, 2017 18:57
Show Gist options
  • Save mikedotexe/c2a5304f47618dbb7dd9c27b8c727457 to your computer and use it in GitHub Desktop.
Save mikedotexe/c2a5304f47618dbb7dd9c27b8c727457 to your computer and use it in GitHub Desktop.
Get homepage path of Drupal 8 site from configuration
<?php
use Drupal\Core\Config\Config;
// ...
$config = \Drupal::config('system.site');
$front_uri = $config->get('page.front');
$alias = \Drupal::service('path.alias_manager')->getAliasByPath($front_uri);
@Ambient-Impact
Copy link

If you're doing this in anything but a procedural function, you should make sure to use dependency injection as using the Drupal global static object is meant only for legacy code and is considered bad practice elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment