modularr/yaml-front-matter

YAML-FrontMatter is a simple to use PHP only FrontMatter type parser Library.

Installs: 167

Dependents: 0

Stars: 17

Watchers: 5

Forks: 8

Language: PHP

1.2.0 2015-05-08 16:09 UTC

README

Latest Version Software License Build Status Total Downloads

An easy to use class for handling YAML frontmatter in PHP.

What does this class do?

YAML Front Matter is a technique used to keep metadata about the file seperated from the actual content inside the file, while still only having one file. This simple PHP class allows you to read such files, and return each of the metadata or content independantly.

What files are compatible with this class?

Any Jekyll file with Front Matter can be parsed by this class.

The format:

The basic format is as follows:

---
foo: bar
title: Test
expl: Make sure there is only 1 space between each of the variables
info: you can have as many custom fields as you like
---
<h1>Text Here</h1>
<p>content</p>

There is no conversion from Markdown so you will have to implement your own.

Requirements:

  • yaml PECL extension for PHP

Installation

via Composer:

{
    "require": {
        "modularr/yaml-front-matter": "1.*"
    }
}

Then run:

composer update

Or install like so:

composer require modularr/yaml-front-matter

make sure you have:

require 'vendor/autoload.php';

Manual:

  1. Download Release Or copy file manually
  2. Include frontmatter.php (found under src/)
  3. Check out the example

How to use

The basic format is as follows:

---
foo: bar
title: Test
expl: Make sure there is only 1 space between each of the variables
info: you can have as many custom fields as you like
---
<h1>Text Here</h1>
<p>content</p>

There is no conversion from Markdown so you will have to implement your own.

Example Code:

$page = new FrontMatter('content/example.md');
echo '<h1><a href="'.$page->fetch('uri').'">'.$page->fetch('title').'</a></h1>
'.$page->fetch('content');