Skip to main content
removed "Drupal" from the title; removed tags from the title
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

base_path Drupal 8 How do I get the base path?

I want to use base paththe base path in drupala Drupal 8 in twigtemplate file,. I try followingstried the following, but no one return anythingI don't get the correct result.

{{ app.request.baseUrl  }}

{{base_path}}

whatWhat I need is the absolute path to the node {{ app.request.baseUrl }}/{{ url }}  .

oneOne solution put thisI found is putting this code in preproccessa preprocess hook, and pass it to the theme.

 $host = \Drupal::request()->getHost(); 
$response = \Drupal::httpClient()

but I looking for better solution I am looking for a better solution. What could should I use instead of the one I am using?

base_path Drupal 8

I want to use base path in drupal 8 in twig file, I try followings but no one return anything

{{ app.request.baseUrl  }}

{{base_path}}

what I need is absolute path to node {{ app.request.baseUrl }}/{{ url }}  .

one solution put this code in preproccess and pass it to theme

 $host = \Drupal::request()->getHost(); 
$response = \Drupal::httpClient()

but I looking for better solution

How do I get the base path?

I want to use the base path in a Drupal 8 template file. I tried the following, but I don't get the correct result.

{{ app.request.baseUrl  }}

{{base_path}}

What I need is the absolute path to the node {{ app.request.baseUrl }}/{{ url }}.

One solution I found is putting this code in a preprocess hook, and pass it to the theme.

 $host = \Drupal::request()->getHost(); 
$response = \Drupal::httpClient()

I am looking for a better solution. What could should I use instead of the one I am using?

Tweeted twitter.com/StackDrupal/status/747922324746289152
Source Link
Yuseferi
  • 22.2k
  • 22
  • 118
  • 218

base_path Drupal 8

I want to use base path in drupal 8 in twig file, I try followings but no one return anything

{{ app.request.baseUrl  }}

{{base_path}}

what I need is absolute path to node {{ app.request.baseUrl }}/{{ url }} .

one solution put this code in preproccess and pass it to theme

 $host = \Drupal::request()->getHost(); 
$response = \Drupal::httpClient()

but I looking for better solution