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
Requires
- php: >=8.1
- symfony/config: ^6.4 || ^7.0 || ^8.0
- symfony/console: ^6.4 || ^7.0 || ^8.0
- symfony/dependency-injection: ^6.4 || ^7.0 || ^8.0
- symfony/filesystem: ^6.4 || ^7.0 || ^8.0
- symfony/finder: ^6.4 || ^7.0 || ^8.0
- symfony/http-client: ^6.4 || ^7.0 || ^8.0
- symfony/http-kernel: ^6.4 || ^7.0 || ^8.0
- symfony/routing: ^6.4 || ^7.0 || ^8.0
- symfony/twig-bundle: ^6.4 || ^7.0 || ^8.0
- twig/twig: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- infection/infection: ^0.29
- phpmetrics/phpmetrics: ^2.8
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^10.5 || ^11.0
- rector/rector: ^1.0
- symfony/asset-mapper: ^6.4 || ^7.0 || ^8.0
- symfony/yaml: ^6.4 || ^7.0 || ^8.0
- vimeo/psalm: ^6.0
This package is auto-updated.
Last update: 2025-11-05 20:18:58 UTC
README
Google Fonts
Google Fonts integration for Symfony
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
- Usage Guide - Detailed examples and function parameters
- Commands - CLI command reference
- Configuration - Configuration options
- Production Setup - Deploying with locked fonts
- Development - Contributing and testing
Requirements
- PHP 8.1 or higher
- Symfony 6.4, 7.x, or 8.x
- Twig 3.0 or higher