PHPackages                             spatie/yaml-front-matter - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. spatie/yaml-front-matter

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

spatie/yaml-front-matter
========================

A to the point yaml front matter parser

2.1.1(5mo ago)3411.8M—3.7%3020MITPHPPHP ^8.0CI passing

Since Jan 14Pushed 5mo ago8 watchersCompare

[ Source](https://github.com/spatie/yaml-front-matter)[ Packagist](https://packagist.org/packages/spatie/yaml-front-matter)[ Docs](https://github.com/sebastiandedeyne/yaml-front-matter)[ Fund](https://spatie.be/open-source/support-us)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/spatie-yaml-front-matter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (18)Used By (20)

yaml-front-matter
=================

[](#yaml-front-matter)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7f018cc7af1e7075dae1abb45487e441614070858e8c2da445544fb651ed97cf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f79616d6c2d66726f6e742d6d61747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/yaml-front-matter)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/b7296b1e14a8438cc8e7fe3fa28481615269b11584fb36473fbd8c377aaa0a02/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7370617469652f79616d6c2d66726f6e742d6d61747465722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/spatie/yaml-front-matter)[![Quality Score](https://camo.githubusercontent.com/88c5ba525d7f873e8fd29ba8215d016ae497978de78fa0faa261a33288a6f217/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f79616d6c2d66726f6e742d6d61747465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/yaml-front-matter)[![Total Downloads](https://camo.githubusercontent.com/2a513b859b97aaa3363e40b188e3f16fbbfcd485bfb51132e901481f9813d527/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f79616d6c2d66726f6e742d6d61747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/yaml-front-matter)

A to the point front matter parser. Front matter is metadata written in yaml, located at the top of a file wrapped in `---`'s.

```
---
title: Example
---

Lorem ipsum.
```

```
use Spatie\YamlFrontMatter\YamlFrontMatter;

$object = YamlFrontMatter::parse(file_get_contents(__DIR__.'/example.md'));

$object->matter('title'); // => 'Example';
$object->body(); // => 'Lorem ipsum.'

// Or retrieve front matter with a property call...

$object->title; // => 'Example';
```

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/8d28f5b0cdedcc10791527f7954ba52ca44d7c4453a51d34199f8dba41e529bd/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f79616d6c2d66726f6e742d6d61747465722e6a70673f743d31)](https://spatie.be/github-ad-click/yaml-front-matter)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Install
-------

[](#install)

You can install the `yaml-front-matter` via composer:

```
$ composer require spatie/yaml-front-matter
```

Usage
-----

[](#usage)

Consider the `example.md` file from above. First you'll need to parse the contents:

```
use Spatie\YamlFrontMatter\YamlFrontMatter;
$object = YamlFrontMatter::parse(file_get_contents('example.md'));
```

The parser will return a `YamlFrontMatterObject`, which can be queried for front matter or it's body.

```
$object->matter(); // => ['title' => 'Example']
$object->matter('title'); // => 'Example'
$object->body(); // => 'Lorem ipsum.'
$object->title; // => 'Example'
```

**Protip**: The `matter` function also accepts dot notation for nested fields, e.g. `matter('meta.keywords')`.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ vendor/bin/phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Sebastian De Deyne](https://github.com/:author_username)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

65

—

FairBetter than 99% of packages

Maintenance70

Regular maintenance activity

Popularity60

Solid adoption and visibility

Community41

Growing community involvement

Maturity77

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~225 days

Recently: every ~332 days

Total

17

Last Release

175d ago

Major Versions

1.1.0 → 2.0.0-rc.12017-08-21

PHP version history (3 changes)1.0.0PHP &gt;=7.0

2.0.6PHP ^7.0|^8.0

2.1.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (41 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (23 commits)")[![emmadesilva](https://avatars.githubusercontent.com/u/95144705?v=4)](https://github.com/emmadesilva "emmadesilva (14 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (10 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (9 commits)")[![IvanBernatovic](https://avatars.githubusercontent.com/u/11651980?v=4)](https://github.com/IvanBernatovic "IvanBernatovic (3 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (3 commits)")[![brendt](https://avatars.githubusercontent.com/u/6905297?v=4)](https://github.com/brendt "brendt (3 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![willemwollebrants](https://avatars.githubusercontent.com/u/916958?v=4)](https://github.com/willemwollebrants "willemwollebrants (2 commits)")[![RobinDev](https://avatars.githubusercontent.com/u/3944894?v=4)](https://github.com/RobinDev "RobinDev (1 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (1 commits)")[![thecaliskan](https://avatars.githubusercontent.com/u/13554944?v=4)](https://github.com/thecaliskan "thecaliskan (1 commits)")[![Tjoosten](https://avatars.githubusercontent.com/u/5157609?v=4)](https://github.com/Tjoosten "Tjoosten (1 commits)")[![vnq](https://avatars.githubusercontent.com/u/28255343?v=4)](https://github.com/vnq "vnq (1 commits)")[![xy2z](https://avatars.githubusercontent.com/u/4496997?v=4)](https://github.com/xy2z "xy2z (1 commits)")[![luceos](https://avatars.githubusercontent.com/u/504687?v=4)](https://github.com/luceos "luceos (1 commits)")[![m1guelpf](https://avatars.githubusercontent.com/u/23558090?v=4)](https://github.com/m1guelpf "m1guelpf (1 commits)")[![mbabker](https://avatars.githubusercontent.com/u/368545?v=4)](https://github.com/mbabker "mbabker (1 commits)")[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (1 commits)")

---

Tags

formattingphpyamlspatieyamljekyllfront matter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spatie-yaml-front-matter/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-yaml-front-matter/health.svg)](https://phpackages.com/packages/spatie-yaml-front-matter)
```

###  Alternatives

[pragmarx/yaml

Load your Laravel config files using yaml

1152.8M29](/packages/pragmarx-yaml)[spatie/sheets

Store &amp; retrieve your static content in plain text files

30187.7k4](/packages/spatie-sheets)[kzykhys/yaml-front-matter

YAML Front-matter Parser/Dumper for PHP

2518.9k1](/packages/kzykhys-yaml-front-matter)[webuni/front-matter

Front matter parser and dumper for PHP

41264.9k11](/packages/webuni-front-matter)[sspooky13/yaml-standards

Standards for yaml files

11518.3k3](/packages/sspooky13-yaml-standards)[thunderer/serializard

Flexible serializer

2767.3k1](/packages/thunderer-serializard)

PHPackages © 2026

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