Content
Stancy uses spatie/sheets to parse your data files. This allows you to use Markdown (with YAML frontmatter), JSON or YAML files.
Before you can start creating content you have to configure your collection(s).
config/sheets.php
<?php
use Spatie\Sheets\ContentParsers\JsonParser;
return [
'default_collection' => 'static',
'collections' => [
'static',
'blog',
'data' => [
'content_parser' => JsonParser::class,
'extension' => 'json',
],
],
];
The above configuration will add three collections
static
, blog
and data
. The first two use the markdown with YAML frontmatter by default but the data
collection uses JSON.The single files in a collection are called "sheet". You have full control over the content of your sheets.
Pages use some predefined variables which you can use to tell the page how to handle the data.
_view
defines the view to use if the page get's rendered_sheets
defines a list of additional sheets or collections to load
static/blog.md
blog/first-post.md
blog/second-post.md
---
_view: page.blog
_pageData: \App\Pages\Blog
_sheets:
posts: blog:*
---
# Blog
---
_view: blog.post
_pageData: \App\Pages\Post
title: my first post
---
---
_view: blog.post
_pageData: \App\Pages\Post
title: my second post
---
These markdown files with YAML frontmatter will generate the following array that's passed to your view.
[
'slug' => 'blog',
'contents' => '<h1>Blog</h1>',
'posts' => [
[
'slug' => 'first-post',
'title' => 'my first post',
],
[
'slug' => 'second-post',
'title' => 'my second post',
]
]
]
This example array does not respect the defined page data classes. Head to the PageData page to learn more about them and what you can do with them.
Last modified 3yr ago