Skip to content
A drop-in flat file CMS for Laravel.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Flat File CMS

Build status StyleCI Status Code coverage Total Downloads Latest Stable Version License

This package contains a drop-in CMS that uses files to store its contents.


You can include this package through Composer using:

composer require roelofjan-elsinga/flat-file-cms

and if you want to customize the folder structure, then publish the configuration through:

php artisan vendor:publish --provider="FlatFileCms\\FlatFileCmsServiceProvider"

Usage of Article

To load all articles located at the folder you specified in config('flatfilecms.articles.folder_path') you can use the following script:

use FlatFileCms\Article;

/**@var Article[]*/
$articles = Article::all();

You can use that to display your posts on a page. You can also load a single post, using:

$article = Article::forSlug($post_slug);

If you only want all published posts, you'll need to retrieve them like so:

$published_articles = Article::published();

To get the contents of the articles.json file, you can run:

$articles = Article::raw();

And finally, to update the data in articles.json, you can run:

$posts = Article::raw();

    'filename' => '', // or: .html, .txt
    'description' => 'This post is about beautiful things',
    'postDate' => date('Y-m-d'),
    'isPublished' => true,
    'isScheduled' => false,


Content blocks

You can also manage small content blocks for your website through this package. Start by specifying the folder path of your content blocks in config('flatfilecms.content_blocks.data_folder').

You'll need to register the facade into your application, by placing the following line to your aliases in config/app.php:

'Block' => \FlatFileCms\Facades\BlockFacade::class,

Now you can use the facade in your views by using:

{!! Block::get('content-file-name') !!}

If you're using content files managed through the CMS, you can also include content blocks in HTML and Markdown files. You can add several different attributes to enhance these content blocks:

  • class
  • id
  • style
  • href

The class, id, and style will be applied to a wrapping div around the content in the block. The link in the href attribute will be applied to a wrapping anchor tag inside the wrapping div.


Using a content block in a HTML or Markdown file managed through the CMS:

<h1>This is a title</h1>

<!--page managed through the CMS-->

<!--resulting HTML output-->
    <h1>This is a title</h1>

Adding a class to the content block:

<h1>This is a title</h1>

<!--page managed through the CMS-->

<!--resulting HTML output-->
<div class="primary-block">
    <h1>This is a title</h1>

Adding multiple classes and a style tag to the content block:

<h1>This is a title</h1>

<!--page managed through the CMS-->
===content[class=block primary-block,style=color:red;]===

<!--resulting HTML output-->
<div class="block primary-block" style="color:red;">
    <h1>This is a title</h1>

When you add a href attribute to the content block, you get a nested anchor tag:

<h1>This is a title</h1>

<!--page managed through the CMS-->

<!--resulting HTML output-->
<div class="primary-block">
    <a href="/link-to-a-page">
        <h1>This is a title</h1>

This facade will look for a file in the folder you specified in config('flatfilecms.content_blocks.data_folder'). The Facade will parse the contents of the file to HTML to be able to render it. If no file could be found, an empty string will be returned.

NOTE: You should not specify the extension of the filename you're passing to Block::get(). This will be parsed automatically.


You can run the included tests by running ./vendor/bin/phpunit in your terminal.

You can’t perform that action at this time.