I have a question about getting a path to an image in a Twig template. The image is not assigned to a field or something. Just a static image which is stored in "MYTHEME/image/icon/my-icon.png".
In Drupal 7 I get the path in my node.template with the following code:
<img src="<?php print base_path() . path_to_theme(); ?>/image/icons">/my-icon.png
How does it work with in Drupal 8? I tried to pass a variable in template_preprocess_node()
.
MYTHEME.theme:
$variables['images_path'] = \Drupal::theme()->getActiveTheme()->getPath() . '/image/';
Twig template:
<img src="{{ images_path ~ 'icons/' ~ 'my-icon.png' }}">
It doesn't work. There is no PHP error, but the path is wrongly said to be http://localhost/node/themes/template/image/icons/my-icon.png.