LogoLogo
10.0.x
10.0.x
  • Overview
    • About Varbase
    • Roadmap
    • Release Cycle and Supported Versions
    • How to Get Support
  • Developers
    • Getting Started
    • Installing Varbase
      • Requirements
      • Installing Varbase locally with DDEV
      • Installing Varbase locally with Lando
    • Understanding Varbase
      • Basic Concepts
      • Core Components
        • Varbase Core
          • Varbase Admin
          • Varbase Page
          • Varbase Security
          • Varbase Webform
          • Varbase Default Content
          • Varbase Tour
        • Varbase Media
        • Varbase Editor
        • Varbase Email
        • Varbase SEO
        • Varbase Workflow
        • Varbase Dashboards
        • Varbase Layout Builder
          • Varbase Landing page (Layout Builder)
          • Varbase Heading Block
          • Varbase Rich Text Block
          • Varbase HTML Code Block
          • Varbase Media (Image/Video) Block
          • Varbase Gallery Block
        • Varbase Components
        • Vartheme Claro
        • Vartheme BS5
      • Optional Components
        • Varbase AI
          • Varbase AI Default recipe
          • Varbase AI Editor Assistant recipe
          • Varbase AI Image Alt recipe
          • Varbase AI Taxonomy Tagging recipe
          • Varbase AI Agents recipe
        • Varbase API
        • Varbase Internationalization
        • Varbase Hero Slider
        • Varbase Carousels
        • Varbase Blog
        • Varbase Search
        • Varbase Social Single Sign-On
        • Varbase Media Twitter
        • Varbase Media Instagram
        • Varbase Content Planner
        • Varbase Bootstrap Paragraphs
          • Varbase Bootstrap Paragraphs Text and Image
        • Varbase Landing Page (Paragraphs)
      • Additional Components
        • Varbase Media Header
        • Varbase FAQs
        • Varbase Reports
        • Varbase Commerce
        • Varbase YouTube Import
      • Development Components
        • Varbase Development
        • Reroute Email
        • Varbase Updates Helper
      • Deprecated Components
        • Varbase Media Hero Slider
        • Varbase Style Guide
        • Vartheme BS4
        • Varbase Total Control Dashboard
    • Configuring a Varbase Site
      • Navigation
        • Defining Active Menu Trail Using Menu Position
      • Using View Modes Inventory
      • Content Moderation and Workflows
      • URL Aliases in Varbase/Drupal
        • Configuring URL Aliases
        • Managing URL Aliases
      • Managing URL Patterns for Multilingual Websites
      • Managing Date and Time Formats to Display Across the Site
      • Using Varbase Layout Builder
        • Creating a Landing Page With Varbase Layout Builder
        • Activating Varbase Layout Builder for Content Types
      • Configuring Pathologic When Going Live
      • Configuring SEO Features
        • Disallow Oembed Media Links
      • Configuring Security Features
        • Spam Protection
        • Password Policies
        • Other Security Kits
        • Flood Contorl
        • Enable HTTP Password Authentication
      • Configuring JSON:API Features
      • Configure Varbase Media Hero Slider
      • Configuring Varbase Media Header
      • Configuring Varbase Mailer Settings
        • Configure Symfony Mailer
      • Configure Level of Logging and Errors
      • Entity Definition Update Manager Class
      • Module Installer Factory Class
      • Configure Ckeditor 5 Media Embed
    • Theme Development with Varbase
      • Understanding The Vartheme Starterkit Theme
      • Creating Your Own Theme
      • Integration of Varbase with Storybook 1.0 - CL Server
      • Integration of Varbase with Storybook 2.0
      • Customize a Varbase Single Directory Components (SDC) In a Custom Theme
      • Local Tasks and Moderation Sidebar
      • Add Preloaded Fonts in Vartheme
      • Command to Install Needed Theming Tools
      • Manually Install Needed Theming Tools
    • Launching a Varbase Site to Production
    • Updating a Varbase Site
      • Understanding Varbase Updater Package
      • Handling Patches When Updating
      • Handling Configuration Updates
      • Updating Varbase to work with Composer 2.0
      • Updating Drush to the Latest Stable Version
      • Version Update Guides
        • Updating Varbase ~9.0 to Drupal 10
        • Updating from Varbase 8.x to 9.x
    • Varbase Patches
    • Frequently Asked Questions (FAQs)
    • Extending Varbase
      • Overriding Varbase
      • Creating Your Own Feature
      • Install Needed YARN and Webpack Tools
      • Compiling Provided Component Styles
      • Check Standards/Practice Coding And Linting
  • Content Designers
    • Accessing the Administration Area
      • Website Environments
    • Dashboard
      • Reports
    • Content Management
      • Create Content
        • Rich-Text Editor “WYSIWYG”
      • Modify Content
      • Delete Content
      • Preview Content
      • Bulk Edit Content
      • Publish Content
      • Authoring Information
    • Content Structure
      • EntityQueues
        • Add a New Term
      • Menu Management
        • Add Menu Items
        • Update Menu Items
        • Adding a Page to the Menu
      • Taxonomies
        • List Terms
        • Add Terms
        • Reorder and Edit Terms
    • Content Translation
      • Translating Content
      • Language Switcher
      • Deleting a Translation
      • Editing a Translation
    • Content Workflow
    • Layout Builder
      • Section
        • Section Styles
      • Block Management
        • Block Styles
      • Reordering Blocks
    • Webforms
      • Create New Webform View
      • Setting up Emails Handler Conditions
      • Setting up Confirmations Message Settings Types
    • Media Management
      • Accessing the Media Library
      • Uploading Media Files
        • Image
        • Remote Video
        • Video
      • Applying Metadata and Descriptions
      • Resizing Images
    • User Management
      • Login & Registration
      • Add User
      • Edit User
      • Delete User
      • Simulating Another User
      • Default Roles and Site Personas
        • Edit Roles' Permissions
        • Managing Roles
    • URL Management
      • URL Aliases
      • Generating URL Alias
      • URL Redirects
      • Domain Redirects
    • SEO Management
      • XML Sitemap
      • Meta Tags in Varbase
      • Disallow Indexing for Content Items
    • Site Configuration
      • System
        • Clearing Varbase Cache
        • Google Analytics
        • Mail Templates
      • User Interface
        • Coffee
        • External Links
        • Gin Moderation Sidebar
        • Layout Builder Modal
        • Moderation Sidebar
        • Shortcuts
        • Taxonomy Manager
        • Tours
        • CL Components
        • Antibot
        • Responsive Preview
        • Navigation Settings
      • Development
      • Varbase Settings
      • Web Services
        • OpenAPI
    • Additional Tips
      • Content Uploading Standards
      • Common Error Handling Tips
      • Glossary
  • Contributing
    • Contributing to Documentation
Powered by GitBook
On this page
  • Steps to Add a New Web Font
  • 1. Add Web Font Files in the Fonts Folder
  • 2. Add the @font-face CSS File to a Library
  • 3. Add the Font to The preload.twig File
  • 4. Clear Cache And Test The Font
  • Content of the Preload.twig File
  • Available Variables
  • Links to Learn by Example
  1. Developers
  2. Theme Development with Varbase

Add Preloaded Fonts in Vartheme

PreviousLocal Tasks and Moderation SidebarNextCommand to Install Needed Theming Tools

Last updated 1 year ago

Following the new way in the new Drupal default front end theme {% include '@olivero/includes/preload.twig' with { olivero_path: olivero_path } only %}

Check the code on

The html.html.twig file

The preload.twig file

Having the following in Vartheme BS5. And the include.

{%- include '@vartheme_bs5/includes/preload.twig' with { vartheme_bs5_path: vartheme_bs5_path, html_dir: html_attributes['dir'] } only -%}

Custom Vartheme Sub Themes are able to add their preloaded assets on demand.

Steps to Add a New Web Font

1. Add Web Font Files in the Fonts Folder

Example: The font

  • Go to the web font page and Download the family.

Download directly from or from the source in

  • Check the license before using the web font

You can use them freely in your products & projects - print or digital, commercial or otherwise.

This isn't legal advice, please consider consulting a lawyer and see the full license for all details.

Not recommended to use not licensed font!

Buy a license if it was possible and budget for a unique branded font.

Or hire a typography font designer.

  • Copy the list of web font files to "PROJECT_PATH/themes/custom/MYTHEME/fonts/lora/webfonts"

  • Create the "PROJECT_PATH/themes/custom/MYTHEME/fonts/lora/css/lora.css" file

  • Define the @font-face for the Lora font.

/*
 * Lora https://fonts.google.com/specimen/Lora
 */
 @font-face {
  font-family: 'Lora';
  font-style: normal;
  font-weight: 400;
  src: url(../webfonts/Lora-Regular.ttf) format('truetype');
}
@font-face {
  font-family: 'Lora';
  font-style: normal;
  font-weight: 700;
  src: url(../webfonts/Lora-Bold.ttf) format('truetype');
}
  src: url(../webfonts/Lora-Regular.eot);
  src: url(../webfonts/Lora-Regular.eot?#iefix) format('embedded-opentype'),
       url(../webfonts/Lora-Regular.woff2) format('woff2'),
       url(../webfonts/Lora-Regular.woff) format('woff'),
       url(../webfonts/Lora-Regular.ttf) format('truetype');

For sure including a remote web font, But issues with preloading may start follow up

2. Add the @font-face CSS File to a Library

  • List the "PROJECT_PATH/themes/custom/MYTHEME/fonts/lora/css/lora.css" file in libraries to be activated in the theme

global-styles:
  css:
    theme:
      fonts/lora/css/lora.css: {}

3. Add the Font to The preload.twig File

Recommended to add for faster loading of font in pages

  • Edit the "PROJECT_PATH/themes/custom/MYTHEME/templates/includes/preload.twig" file. Add the link rel preload and the patch to the font file with as="font" and type

<link rel="preload" href="/{{ vartheme_bs5_path }}/fonts/lora/Lora-Regular.ttf" as="font" type="font/tff" crossorigin="anonymous">

4. Clear Cache And Test The Font

Content of the Preload.twig File

Change the logic in this file in the generated theme for the project. To match the need of your website.

Available Variables

  • vartheme_bs5_path: Returns the path to the Vartheme BS5 theme. In the generated cloned Vartheme theme, the variable could be mythemename_path

  • html_dir: contains the language direction. It will either be 'ltr' or 'rtl'.

Example of logic:

  • Multilingual websites may use a language selection for preloaded assets.

  • Sections of the website may have a custom prelead assets for CSS/JS.

Links to Learn by Example

Check the following links:

Vartheme Fonts folder:

These fonts are licensed under the .

Having more file formats if that was available by

Example: The font

Have a look at "Preload critical assets to improve loading speed" for more ideas on what/when/where to use preload.

Vartheme html.html.twig file:

Vartheme preload.twig file:

Preload critical assets to improve loading speed
Preload W3C Candidate Recommendation 26 June 2019
Olivero
Olivero
https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/themes/olivero/templates/layout/html.html.twig#L43
https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/themes/olivero/templates/includes/preload.twig
Lora
Lora
fonts.google.com
github.com
https://github.com/cyrealtype/Lora-Cyrillic
Open Font License
web font conversion tools
Lora
https://web.dev/preload-critical-assets/
https://git.drupalcode.org/project/vartheme_bs5/-/tree/3.0.x/fonts
https://git.drupalcode.org/project/vartheme_bs5/-/blob/3.0.x/templates/system/html.html.twig#L50
https://git.drupalcode.org/project/vartheme_bs5/-/blob/3.0.x/templates/includes/preload.twig