All Projects → webuni → front-matter

webuni / front-matter

Licence: MIT license
The most featured front matter (yaml, json, neon, toml) parser and dumper for PHP.

Programming Languages

PHP
23972 projects - #3 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to front-matter

Migrify
Futuristic Grinder for Legacy Code with Effortles Confidence
Stars: ✭ 25 (+8.7%)
Mutual labels:  yaml, twig, neon
Config
📝 Go config manage(load,get,set). support JSON, YAML, TOML, INI, HCL, ENV and Flags. Multi file load, data override merge, parse ENV var. Go应用配置加载管理,支持多种格式,多文件加载,远程文件加载,支持数据合并,解析环境变量名
Stars: ✭ 225 (+878.26%)
Mutual labels:  yaml, toml
Python Benedict
dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. 📘
Stars: ✭ 204 (+786.96%)
Mutual labels:  yaml, toml
climatecontrol
Python library for loading settings and config data from files and environment variables
Stars: ✭ 20 (-13.04%)
Mutual labels:  yaml, toml
Fig
A minimalist Go configuration library
Stars: ✭ 142 (+517.39%)
Mutual labels:  yaml, toml
Simple Settings
A simple way to manage your project settings.
Stars: ✭ 165 (+617.39%)
Mutual labels:  yaml, toml
Cli
A simple, fast, and fun package for building command line apps in Go
Stars: ✭ 16,995 (+73791.3%)
Mutual labels:  yaml, toml
Night Config
Powerful java configuration library for toml, yaml, hocon, json and in-memory configurations
Stars: ✭ 93 (+304.35%)
Mutual labels:  yaml, toml
config-cpp
C++ Configuration management library inspired by the Viper package for golang.
Stars: ✭ 21 (-8.7%)
Mutual labels:  yaml, toml
remark-frontmatter
remark plugin to support frontmatter (YAML, TOML, and more)
Stars: ✭ 167 (+626.09%)
Mutual labels:  yaml, toml
paerser
No description or website provided.
Stars: ✭ 38 (+65.22%)
Mutual labels:  yaml, toml
Rq
Record Query - A tool for doing record analysis and transformation
Stars: ✭ 1,808 (+7760.87%)
Mutual labels:  yaml, toml
Gray Matter
Contributing Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Stars: ✭ 2,105 (+9052.17%)
Mutual labels:  yaml, front-matter
Grav
Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
Stars: ✭ 13,067 (+56713.04%)
Mutual labels:  yaml, twig
Datafiles
A file-based ORM for Python dataclasses.
Stars: ✭ 113 (+391.3%)
Mutual labels:  yaml, toml
Konf
A type-safe cascading configuration library for Kotlin/Java/Android, supporting most configuration formats
Stars: ✭ 225 (+878.26%)
Mutual labels:  yaml, toml
cfg-rs
A Configuration Library for Rust Applications
Stars: ✭ 18 (-21.74%)
Mutual labels:  yaml, toml
Re Txt
converts text-formats from one to another, it is very useful if you want to re-format a json file to yaml, toml to yaml, csv to yaml, ... etc
Stars: ✭ 59 (+156.52%)
Mutual labels:  yaml, toml
Config Lite
A super simple & flexible & useful config module.
Stars: ✭ 78 (+239.13%)
Mutual labels:  yaml, toml
wildq
Command-line TOML/JSON/INI/YAML/XML/HCL processor using jq c bindings
Stars: ✭ 22 (-4.35%)
Mutual labels:  yaml, toml

Front Matter

Packagist Build Status Scrutinizer Code Quality Code Coverage

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

Parse an arbitrary string

<?php

$frontMatter = new \Webuni\FrontMatter\FrontMatter();

$document = $frontMatter->parse($string);

$data = $document->getData();
$content = $document->getContent();

Check if a string has front matter

<?php

$frontMatter = new \Webuni\FrontMatter\FrontMatter();

$hasFrontMatter = $frontMatter->exists($string);

Twig loader

If you want to store metadata about twig template, e.g.:

{#---
title: Hello world
menu: main
weight: 20
---#}
{% extend layout.html.twig %}
{% block content %}
Hello world!
{% endblock %}

you can use FrontMatterLoader, that decorates another Twig loader:

$frontMatter = \Webuni\FrontMatter\Twig\TwigCommentFrontMatter::create();
$loader = new \Twig\Loader\FilesystemLoader(['path/to/templates']);
$loader = new \Webuni\FrontMatter\Twig\FrontMatterLoader($frontMatter, $loader);

$twig = new \Twig\Environment($loader);
$content = $twig->render('template', []);
// rendered the valid twig template without front matter

It is possible to inject front matter to Twig template as variables:

// …
$converter = \Webuni\FrontMatter\Twig\DataToTwigConvertor::vars();
$loader = new \Webuni\FrontMatter\Twig\FrontMatterLoader($frontMatter, $loader, $converter);
// …

Loaded Twig template has this code:

{% set title = "Hello world" %}
{% set menu = "main" %}
{% set weight = 20 %}
{% line 5 %}
{% extend layout.html.twig %}
{% block content %}
Hello world!
{% endblock %}

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:

---
layout: post
title: I Love Markdown
tags:
  - test
  - example
---

# Hello World!

This library can be used with league/commonmark:

$frontMatter = new \Webuni\FrontMatter\FrontMatter();
$extension = new \Webuni\FrontMatter\Markdown\FrontMatterLeagueCommonMarkExtension($frontMatter);

$environment = \League\CommonMark\Environment::createCommonMarkEnvironment();
$environment->addExtension($extension);

$converter = new \League\CommonMark\CommonMarkConverter([], $environment);
$html = $converter->convertToHtml('markdown'); // html without front matter

Alternatives

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].