Giter Club home page Giter Club logo

yaml-frontmatter's Introduction

YAML Front Matter

Latest Version Software License Build Status Total Downloads

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

What does this class do?

This class is a PHP implementation of Jekyll Front Matter.

Any file that contains a YAML front matter block will be processed 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. Here is a basic example:

---
layout: post
title: Blogging Like a Hacker
---

Between these triple-dashed lines, you can set variables using YAML. You can access them via the fetch function. Conversion to Markdown is optional.

How to use

$page = new \Modularr\YAMLFrontmatter\FrontMatter('content/example.md');

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

foreach($page->fetch('list') as $key => $value) {
    echo '<li>'.$key.' => '.$value.'</li>';
}
$array = $page->fetch('list');
echo $array['foo'];
---
foo: bar
title: Test
info: you can have as many custom fields as you like
date: 2005-09-16 17:20:42+00:00
layout: post
comments: true
slug: testing
list: { foo: bar, bar: baz }
list2:
- foo
- bar
list3:
    foo: bar
    bar: baz
---
<h1>Text Here</h1>
<p>content</p>

Installation

Install in via Composer:

composer require modularr/yaml-front-matter

If you are using the package in a VanillaJS project make sure you have:

require_once 'vendor/autoload.php';

yaml-frontmatter's People

Contributors

dinglidingli avatar istpdev avatar mre avatar pbakaus avatar spekulatius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.