8.2.x common.inc base_path()
8.0.x common.inc base_path()
8.1.x common.inc base_path()
8.3.x common.inc base_path()
4.7.x common.inc base_path()
5.x common.inc base_path()
6.x common.inc base_path()
7.x common.inc base_path()

Returns the base URL path (i.e., directory) of the Drupal installation.

base_path() adds a "/" to the beginning and end of the returned path if the path is not empty. At the very least, this will return "/".


36 calls to base_path()
AttachedAssetsTest::testAggregation in core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php
Integration test for CSS/JS aggregation.
BigPipePlaceholderTestCases::cases in core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php
Gets all BigPipe placeholder test cases.
BigPipeTest::testNoJsDetection in core/modules/big_pipe/src/Tests/BigPipeTest.php
Tests BigPipe's no-JS detection.
color_scheme_form_submit in core/modules/color/color.module
Form submission handler for color_scheme_form().
CommentInterfaceTest::testCommentInterface in core/modules/comment/src/Tests/CommentInterfaceTest.php
Tests the comment interface.

... See full list

14 string references to 'base_path'
AlreadyInstalledException::__construct in core/lib/Drupal/Core/Installer/Exception/AlreadyInstalledException.php
Constructs a new "already installed" exception.
ColorTest::testLogoSettingOverride in core/modules/color/tests/src/Functional/ColorTest.php
Test whether the custom logo is used in the color preview.
DefaultSummary::buildOptionsForm in core/modules/views/src/Plugin/views/style/DefaultSummary.php
Provide a form to edit options for this plugin.
DefaultSummary::defineOptions in core/modules/views/src/Plugin/views/style/DefaultSummary.php
Information about options for all kinds of purposes will be held here.
FieldPluginBaseTest.php in core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
Contains \Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTest.

... See full list


core/includes/common.inc, line 413
Common functions that many Drupal modules will need to reference.


function base_path() {
  return $GLOBALS['base_path'];


josueValRob’s picture

i have a custom module, and a custom block... how can i call this variable from my example.html.twig file?

v7nguyen’s picture

Hi! I was just looking this up too, you would call it in the "*.module" file using the preprocess override hook, ex:

function hook_preprocess_html(&$variables) {
  $variables['page_url'] = \Drupal::request()->getRequestUri();

Then, use the {{ page_url }} in your *html.twig file.

Anyone else, please feel free to correct me if I am wrong :)