PHPackages                             parisek/twig-typography - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. parisek/twig-typography

ActiveLibrary[Templating &amp; Views](/categories/templating)

parisek/twig-typography
=======================

A Twig extension with typography filter

v1.2.3(1mo ago)14.2k↑480%2GPL-2.0-or-laterPHPPHP ^8.3CI passing

Since Mar 2Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/parisek/twig-typography)[ Packagist](https://packagist.org/packages/parisek/twig-typography)[ Docs](https://github.com/parisek/twig-typography)[ RSS](/packages/parisek-twig-typography/feed)WikiDiscussions main Synced today

READMEChangelog (9)Dependencies (25)Versions (16)Used By (2)

Twig Typography Extension
=========================

[](#twig-typography-extension)

Twig adapter for [PHP-Typography](https://github.com/mundschenk-at/php-typography) — smart quotes, dashes, ellipses, hyphenation, widow protection, fraction glyphs, ordinal suffixes, math symbols, CSS hooks for styling.

Requirements
------------

[](#requirements)

- PHP 8.3+
- Twig 3 or 4
- Symfony YAML 6, 7, or 8 (always installed as a hard dependency; only invoked at runtime when the constructor receives a `.yml` file path)

Installation
------------

[](#installation)

```
composer require parisek/twig-typography
```

Usage
-----

[](#usage)

### Register on a Twig environment

[](#register-on-a-twig-environment)

```
use Parisek\Twig\TypographyExtension;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;

$twig = new Environment(new FilesystemLoader('/path/to/templates'));

// Library defaults — sane English settings.
$twig->addExtension(new TypographyExtension());

// — or — load settings from a YAML file:
$twig->addExtension(new TypographyExtension(__DIR__ . '/typography.yml'));

// — or — pass settings as a PHP array (no filesystem):
$twig->addExtension(new TypographyExtension([
    'set_smart_quotes' => true,
    'set_smart_dashes' => true,
]));
```

### In templates

[](#in-templates)

```
{{ title|typography }}

{{ "Lorem ipsum"|typography }}

{# Override constructor defaults for one call: #}
{{ title|typography({ set_smart_dashes: false }) }}
```

The filter is `is_safe: html` — its output may contain ``, ``, and similar markup, and is emitted unescaped.

Configuration
-------------

[](#configuration)

Every key in your YAML or array becomes a method call on [PHP-Typography's `Settings` class](https://github.com/mundschenk-at/php-typography/blob/main/src/class-settings.php). The library's full `Settings(true)` defaults are applied first; your values override them.

### Example: Czech (`cs-CZ`) settings

[](#example-czech-cs-cz-settings)

```
# typography.yml — Czech smart typography
set_diacritic_language: "cs"

# Smart quotes — Czech style „double" and ‚single'
set_smart_quotes: TRUE
set_smart_quotes_primary: "doubleLow9"      # „ … "
set_smart_quotes_secondary: "singleLow9"    # ‚ … '

# Smart dashes — Czech/EU: en-dash with spaces (not US em-dash)
set_smart_dashes: TRUE
set_smart_dashes_style: "international"

# Smart spacing
set_single_character_word_spacing: TRUE     # k/s/v/z/o/u/i/a + nbsp — required in CZ
set_unit_spacing: TRUE                      # "5 kg" → "5&nbsp;kg"
set_dewidow: FALSE                          # last-line widow protection — bad for responsive layouts

# Wrapping helpers
set_hyphenation: FALSE                      # leave to CSS `hyphens: auto` + `lang="cs"`
set_url_wrap: FALSE
set_email_wrap: FALSE
```

What's not included
-------------------

[](#whats-not-included)

This extension exposes PHP-Typography as **one Twig filter**, `|typography`. There's no `{% typography %}` block tag (despite earlier versions of this README claiming one — the tag was never implemented in code). To apply typography to a block of HTML, wrap it in an element and apply the filter to the rendered string, or define a [Twig macro](https://twig.symfony.com/doc/3.x/tags/macro.html)that encapsulates the pattern you want.

License
-------

[](#license)

GPL-2.0-or-later, see `LICENSE.txt`.

Inspiration
-----------

[](#inspiration)

- [Twig Extension Symfony Bundle](https://github.com/debach/typography-bundle)
- [Twig Typography Drupal Module](https://www.drupal.org/project/twig_typography)

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance94

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 94.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~239 days

Recently: every ~149 days

Total

9

Last Release

32d ago

PHP version history (2 changes)v1.0PHP &gt;=7.3.0

v1.2.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f60a7484412a046d60bd8de9c5fb773cd9d59f00a1b455284fa718b786a4d93?d=identicon)[parisek](/maintainers/parisek)

---

Top Contributors

[![parisek](https://avatars.githubusercontent.com/u/10908003?v=4)](https://github.com/parisek "parisek (16 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

phptwigtwig-extensiontypographytwigtypography

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/parisek-twig-typography/health.svg)

```
[![Health](https://phpackages.com/badges/parisek-twig-typography/health.svg)](https://phpackages.com/packages/parisek-twig-typography)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.7k](/packages/drupal-core)[symfony/ux-twig-component

Twig components for Symfony

22018.6M356](/packages/symfony-ux-twig-component)[symfony/ux-toolkit

A tool to easily create a design system in your Symfony app with customizable, well-crafted Twig components

16126.1k1](/packages/symfony-ux-toolkit)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M421](/packages/drupal-core-recommended)[symfony/ux-live-component

Live components for Symfony

1647.0M128](/packages/symfony-ux-live-component)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
