Hello
I'm facing a problem with image url path in theme.
I created a custom theme from classy base. In html.html.twig, in the beginning of the document, I added image with
<img src="{{ base_path ~ directory }}/img/header.jpg" alt="image"/>
This image works fine in http://localhost/drupal/ and http://localhost/drupal/node/2.
Drupal considers that image is stocked on http://localhost/drupal/themes/custom/name_of_my_theme/img/header.jpg
I decided to add it in footer region so I put the same code in a file called region--footer.html.twig
This second image works fine in http://localhost/drupal/ but not in http://localhost/drupal/node/2
Indeed, in this page, Drupal considers this 2nd image as stocked on
http://localhost/drupal/node/themes/custom/name_of_my_theme/img/header.jpg
As you can notice, it considers now the base path as http://localhost/drupal/node/
What am I doing wrong? What can I do to fix it?
Thanks a lot
Comments
I found solution by using
I found solution by using following code :
<img src="{{ url('<front>') }}{{ directory }}/img/header.jpg" alt="image"/>
If anyone needs it...