Download the PHP package webuni/front-matter without Composer
On this page you can find all versions of the php package webuni/front-matter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webuni/front-matter
More information about webuni/front-matter
Files in webuni/front-matter
Package front-matter
Short Description Front matter parser and dumper for PHP
License MIT
Homepage https://github.com/webuni/front-matter
Informations about the package front-matter
Front Matter
The most universal Front matter (yaml, json, neon, toml) parser and dumper for PHP. Front matter allows page-specific variables to be included at the top of a page.
Installation
This library can be installed via Composer:
composer require webuni/front-matter
Usage
Automatic front matter detection and parsing
This library can parse all form of front matter:
YAML (Neon) | TOML | Twig | Pug | Json |
---|---|---|---|---|
The following code will automatically detect the above front matter types:
Parse an arbitrary string
Check if a string has front matter
Twig loader
If you want to store metadata about twig template, e.g.:
you can use FrontMatterLoader
, that decorates another Twig loader:
It is possible to inject front matter to Twig template as variables:
Loaded Twig template has this code:
Available converters:
Converter | Twig |
---|---|
DataToTwigConvertor::nothing() |
|
DataToTwigConvertor::vars() |
{% set key1 = value1 %} |
DataToTwigConvertor::vars(false) |
{% set key1 = key1 is defined ? key1 : value1 %} |
DataToTwigConvertor::var('name') |
{% set name = {key1: value1, key2: value2} %} |
DataToTwigConvertor::var('name', false) |
{% set name = name is defined ? name : {key1: value1} %} |
Markdown
The most commonly used front matter is for markdown files:
This library can be used with league/commonmark: