I am trying to write a FQDN path to a image in my theme directory within a Views custom text box.
My install of Drupal is in a sub-directory so relative paths do not work correctly.
Here is what I have in my Views custom text box.

<img alt="Document Icon" class="ico" src="{{ base_path ~ active_theme_path() }}/images/svg/ico-document.svg">

'base_path' comes up empty. I have tried 'base_path' and 'base_path()'. If I use 'base_path()' then I get "unknown "base_path" function". The 'active_theme_path()' does return the path to the theme directory.

I even tried setting '$variables['base_path'] = base_path();' in preprocess which works in .twig templates but not within a Views custom text box.

Any assistance greatly appreciated!

Comments

slewazimuth’s picture

$base_url might be what you want for preprocess. Check out this info.

ksavoie’s picture

You would be right however I need its value in a Views custom text box, and how to get it there is alluding me.
I'm green to D8 so I must be missing something as I would have thought that there would have been a twig equivalent to $base_url that can be processed in that View/twig context.

slewazimuth’s picture

Write a twig function for the $base_url answer I gave you and it will work just fine in a Views custom text box. Documentation

jeromewiley’s picture

How would you recommend to write this Twig function?

(subscribe)