Phrontmatter v1.3.0

Today I tagged the v1.3.0 release of the Phrontmatter package.

If you're unsure what package does or even what Front Matter is, then here is a quick rundown for you.

What is Front Matter?

Front Matter is a feature of the Jekyll blogging platform.

Any file that contains a YAML front matter block will be processed by Jekyll as a special file. The front matter must be the first thing in the file and must take the form of valid YAML set between triple-dashed lines

[..]

Between these triple-dashed lines, you can set predefined variables [..] or even create custom ones of your own. These variables will then be available to you to access using Liquid tags both further down in the file and also in any layouts or includes that the page or post in question relies on.

An example of a document using Front Matter:

---
title: Hello World  
slug: hello-world  
author: James Brooks  
---

This is normal **Markdown** content. How simple is this document!?  

What is Phrontmatter?

Phrontmatter is a PHP implementation of the Front Matter parser. Aside from YAML, Phrontmatter also supports both TOML and JSON formats (in case YAML isn't your thing).

Using Phrontmatter is really simple! For one, it's a Composer package, so installation is simply:

$ composer require bluebaytravel/phrontmatter

Parsing a document with Phrontmatter can be done in a couple of different ways; the Facade or class injection.

// Parse a document.
Phrontmatter::parse("---\nfoo: bar---\nThis is actual content!")->foo;

// Dependency injection example.
$phrontmatter->parse("---\nfoo: bar---\nThis is actual content!")->getContent();

// Parse a document with JSON meta data.
$phrontmatter->parse("---\n{\"foo\":\"bar\"}\n---\nThis is a document with JSON!", Phrontmatter::JSON)->getData();

comments powered by Disqus