yaml-front-matter

A to the point yaml front matter parser

  • Owner: spatie/yaml-front-matter
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

yaml-front-matter

Latest Version on Packagist
Software License
Build Status
Quality Score
Total Downloads

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.
$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.

Install

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

$ composer require spatie/yaml-front-matter

Usage

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

$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

Please see CHANGELOG for more information what has changed recently.

Testing

$ vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.

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, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

Support us

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Does your business depend on our contributions? Reach out and support us on Patreon.
All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

License

The MIT License (MIT). Please see License File for more information.

Overview

Name With Ownerspatie/yaml-front-matter
Primary LanguagePHP
Program languagePHP (Language Count: 1)
Platform
License:MIT License
Release Count14
Last Release Name2.0.8 (Posted on )
First Release Name1.0.0 (Posted on )
Created At2016-01-13 21:26:46
Pushed At2023-12-04 10:03:30
Last Commit At
Stargazers Count322
Watchers Count10
Fork Count28
Commits Count110
Has Issues Enabled
Issues Count0
Issue Open Count0
Pull Requests Count21
Pull Requests Open Count0
Pull Requests Close Count5
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private
To the top