how we can print base_url in js file (in drupal)?please
2 Answers
Drupal 7
Drupal.settings.basePath
Drupal 8
drupalSettings.path.baseUrl
1 Comment
vkvkvk
For me the drupalSettings.path.baseUrl prints "/" and not the actual base url (e.g. example.dev) of the website. Do I miss any extra steps?
You can use $base_path. See en example on The Drupal JavaScript API under the "Drupal.settings" section.
1 Comment
Jonathan Bergeron
This would be usefull only if you are dealing with both PHP and Javascript (define your setting in a custom PHP module, load it in Javascript, than access it). For any other custom setting, this is worth it. But for the base path, I think yoavmatchulsky answer is best.