Skip to content

Instantly share code, notes, and snippets.

@steffenr
Created August 11, 2016 18:07
Show Gist options
  • Save steffenr/303c8ee147f9e7983de35557f35c5ae1 to your computer and use it in GitHub Desktop.
Save steffenr/303c8ee147f9e7983de35557f35c5ae1 to your computer and use it in GitHub Desktop.
Embed external fonts in Drupal 8 theme (fonts are added in custom themename.libraries.yml)
name: Theme name
type: theme
description: Theme description
package: Custom
core: 8.x
libraries:
- themename/fonts
- themename/global-styling
base theme: classy
# Regions
regions:
header: 'Header'
primary_menu: 'Navigation'
highlighted: 'Preface'
content: 'Content'
footer: 'Footer'
fonts:
license:
name: Apache License, 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
css:
theme:
'//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800': { type: external }
global-styling:
version: 1.x
css:
theme:
css/bootstrap/bootstrap.min.css: {}
css/custom.css: {}
js:
js/bootstrap.min.js: {}
js/custom.js: {}
dependencies:
- core/jquery
- core/jquery.once
@aon8
Copy link

aon8 commented Jul 2, 2018

thanks for this but how would it be if one wants to embed local fonts (in the theme folder). I tried with @font-face in the css but didn't seem to work !

@aon8
Copy link

aon8 commented Jul 5, 2018

That's how I did it for local fonts as well. I just added the fonts.css to the mytheme.libraries.yml file under global-styling and that's all. The fonts files and fonts.css are in theme/assets/fonts/ and the fonts.css has the fonts info and local urls.

Only one of my 4 used fonts is working though and I have yet to figure out why the rest aren't working !!!

Anyone here at all :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment