neuralglitch/google-fonts

Google Fonts integration for Symfony with development CDN and production font locking

Installs: 122

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 0

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/neuralglitch/google-fonts

0.2.0 2025-11-05 20:13 UTC

This package is auto-updated.

Last update: 2025-11-05 20:18:58 UTC


README

Google Fonts

Google Fonts integration for Symfony

PHP Version Symfony
PHPUnit Coverage PHPStan
Psalm Infection Code Style
Release Downloads License

Features

  • Twig Function - Simple {{ google_fonts() }} function
  • Development Mode - Google Fonts CDN with inline styles
  • Production Mode - Lock fonts locally for better performance and privacy
  • Smart CSS - Automatic font styling for body, headings, and bold text
  • CLI Tools - Search, import, lock, and warm-cache commands
  • High Performance - Optimized with full template caching support

Prerequisites

For fully automatic setup, visit the related Flex recipe repository and follow the instructions to add it to the composer.json in the consuming project, as the recipe is not yet part of the Symfony’s main recipe repository.

Installation

composer require neuralglitch/google-fonts

Quick Start

1. Add fonts to your template

{# templates/base.html.twig #}
<head>
  {# Normal font for body and headings #}
  {{ google_fonts('Ubuntu', '300 400 500 700', 'normal italic') }}
  
  {# Monospace font for code elements #}
  {{ google_fonts('JetBrains Mono', '400 500', 'normal', null, true) }}
</head>

2. Lock fonts for production

php bin/console gfonts:lock

This downloads fonts to assets/fonts/ (served by AssetMapper in dev, compiled to public/ in prod).

Each font gets a single CSS file containing both @font-face declarations and intelligent styling rules.

The bundle automatically switches to locked fonts in production (via when@prod configuration).

Troubleshooting: If locked fonts aren't being used in production, see DEBUG_LOCKED_FONTS.md.

3. Optional: Configure API key for search/import commands

# .env.local
GOOGLE_FONTS_API_KEY=your_api_key_here

Get your free API key at Google Cloud Console.

Note: The API key is only required for gfonts:search and gfonts:import commands. The google_fonts() Twig function and gfonts:lock command do NOT require an API key.

Documentation

Requirements

  • PHP 8.1 or higher
  • Symfony 6.4, 7.x, or 8.x
  • Twig 3.0 or higher

Support

License

MIT