Skip to content

Front Matter

In a nutshell: Front Matter is a block of YAML containing metadata, stored at the top of a Markdown file.

Front matter is heavily used in HydePHP to store metadata about pages. Hyde uses the front matter data to generate rich and dynamic content. For example, in a blog post you may define a category, author website, or featured image. In a documentation page you may define the sidebar priority or label.

Using front matter is optional, as Hyde will dynamically generate data based on the content itself. (Though any matter you provide will take precedence over the automatically generated data.) While Hyde offers some support for front matter within Blade files, most of the time you use front matter, it will be in Markdown.

Front Matter Syntax

Here's a refresher on Yaml, and a quick reference of the syntax Hyde uses and expects:

1---
2key: value
3string: "quoted string"
4boolean: true
5integer: 100
6array:
7 key: value
8 key: value
9---

Strings don't need to be quoted, but it can help in certain edge cases, thus they are included here.

Front Matter in Markdown

All Markdown content files support Front Matter. Blog posts for example make heavy use of it.

The specific usage and schemas used for pages are documented in their respective documentation, however, here is a primer on the fundamentals.

  • Front matter is stored in a block of YAML that starts and ends with a --- line.
  • The front matter should be the very first thing in the Markdown file.
  • Each key-pair value should be on its own line.

To use Front Matter, add Yaml to the top of your Markdown file:

1---
2title: "My New Post"
3author:
4 name: "John Doe"
5 website: https://example.com
6---
7 
8## Markdown comes here
9 
10Lorem ipsum dolor sit amet, etc.

Front Matter in Blade

HydePHP has experimental support for creating front-matter in Blade templates, called BladeMatter.

The actual syntax does not use YAML; but instead PHP. However, the parsed end result is the same. Please note that BladeMatter currently does not support multidimensional arrays or multi-line directives as the data is statically parsed.

To create BladeMatter, you simply use the default Laravel Blade @php directive to declare a variable in the template.

1@php($title = 'BladeMatter Demo')

It will then be available through the global $page variable, $page->matter('title'). Hyde will of course also use the data for contextual autoconfiguration in the same way it would with Markdown and use the value as the page title.

Another idea is to use @php($navigation = ['hidden' => true]) if you want to hide a page from the navigation. The opportunities are limitless!