-2

I would like you something about font paths and font caching in Drupal 8 (8.7.2).

My aim is to use a custom font, without using the @font-your-face-module.

Just for trying out, on my local installation, I added the font-family in line 17 of core/themes/bartik/css/components/site-branding.css

At this moment, my font file resides on my desktop folder, Drupal chaching is disabled.

Actually, the font is displayed correctly – no need to put the font file in a drupal directory, no need to define any path to the font file.

How can this work? How does Drupal know from where to pull the font?

Even stranger, the fonts remains displayed correctly even after deleting the font file from desktop and performing cache deletion in Drupal.

Can someone figure out how Drupal pulls and stores fonts?

Thank you very much in advance

  • 2
    Please make the question a little more specific and give actual code instead of describing what you did (which sometimes can be hard to understand). In general the font defined in css files are up to the browser to decide where to pull them from, drupal can actually give extra instructions of where to look for them . I think all modern browsers will first look in the native OS environment to see if the font exists there and if not they will fall back to another more generic font. Perhaps this custom font is actually installed in your operating system ? – GiorgosK Jun 16 at 8:38
  • Thank you very much, GiorgosK, your last sentence was the solution: The font is actually installed in the OS. – J. Doe Jun 16 at 9:09
  • I'm now trying to use a custom font which is not OS enabled. According to multiple instructions I did the following: In mytheme.info.yml : libraries: - mytheme/fonts In mytheme.libraries.yml : fonts: css: theme: myfont.css In themes/mytheme there is a folder "font" with two files: - myfont.woff - myfont.css The main css: @font-face { font-family:"Myfont"; src: url("myfont.woff") format("woff"), font-style:normal; font-weight:400; } Whatever I try the – the font doesn't show up... any idea? Again thank you very much! – J. Doe Jun 16 at 11:53
  • please either make this part of your question with proper formatting or create a new question. – GiorgosK Jun 16 at 13:43
  • Thank you Giorgios, unfortunately i can't add much formatting... I'm now trying to use a custom font which is not OS enabled. According to multiple instructions I did the following: In mytheme.info.yml : libraries: - mytheme/fonts' In mytheme.libraries.yml : fonts: css: theme: myfont.css In themes/mytheme there is a folder "font" with two files: "myfont.woff" & "myfont.css". The main css: @font-face { font-family:"Myfont"; src: url("myfont.woff") format("woff"), font-style:normal; font-weight:400; } Whatever I try the – the font doesn't show up... any idea? Again thank you very much! – J. Doe Jun 16 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.