[Drupal] How to use the global path variable in Drupal

| | 1 min read

In Drupal we use the global path variables for specific reasons.
If in any case there is a change in your site url you just have to update the general configuration page and by doing so every link in your site would be automatically updated. Using the path variable is also less prone to errors.Read on to know how to use the global path variable in Drupal

Here are the most commonly used path variables in drupal

$base_root
$base_url
$base_path

Suppose our site is hosted at http://www.example.com/examplesite

The $base_root would give the URL of the host, excluding the path.
$base_root would return http://www.example.com

The $base_url does not include the trailing slash.
$base_url would return http://www.example.com/examplesite

The $base_path would give the base url of the drupal installation
$base_path would return /examplesite/

This is a brief and basic description of how you can use the global path variables on a site. Get in touch with us for any Drupal specific help you might need on your Drupal site.