Markdown files based Bundle to integrate a simple blog in your Symfony application

1.0.2 2017-12-22 14:06 UTC


Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage License

Markdown files based Bundle to integrate a simple blog in your Symfony application



Require the bundle

$ composer require matks/markdown-blog-bundle

Enable the bundle in your Symfony application

    // app/AppKernel.php

    public function registerBundles()
        $bundles = array(
            // ...
            new \Matks\MarkdownBlogBundle\MarkdownBlogBundle(),

Configure the bundle

    posts_directory: 'path_to_my_markdown_docs'


Write your Markdown posts using your favorite Markdown Editor. Then copy them in your folder posts_directory.

The post title will be parsed from the file name.

Write a library_register.yml file in the folder posts_directory which will provide your posts metadata.



        date: '2016-04-01'
        category: Blog

        date: '2016-04-01'
        category: Blog

        date: '2016-05-01'
        category: Dev
        tags: ['github', 'open-source']

For each blog entry, the entry name must match the Markdown file name. Available metadata is

  • date (string, format YYYY-MM-DD)
  • category (string)
  • tags (array of strings)
  • alias (string) ; overrides your post name

If there is a file but no entry in the register, the Post will still be available, however the publish date will be computed from the file creation timestamp.

That's it ! Your blog data structure is available through the service markdown_blog.library (class Library).

You can get your posts using the following functions:

$library = $this->get('markdown_blog.library');

/** @var Post[] $allPosts */
$allPosts = $library->getAllPosts();

/** @var boolean $isPostRegistered */
$isPostRegistered = $library->isPostRegistered();

/** @var Post $post */
$post = $library->getPostByName();

/** @var Post[] $posts */
$posts = $library->getPostsByName();

/** @var Post[] $posts */
$posts = $library->getPostsByDate();

/** @var Post[] $posts */
$posts = $library->getPostsByCategory();

/** @var Post[] $posts */
$posts = $library->getPostsByTag();

You can now display your blog using any template you want. Example:


namespace AppBundle\Controller;

use Matks\MarkdownBlogBundle\Blog\Library;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class BlogController extends Controller
    public function indexAction(Request $request)
        $library = $this->getLibrary();
        $allPosts = $library->getAllPosts();

        return $this->render(
            ['posts' => $allPosts]

     * @return Library
    private function getLibrary()
        return $this->get('markdown_blog.library');

You can have a look at the markdown-blog-bundle-example. It displays a blog using bootstrap templates.


Stand alone context

In a bundle isolation context, just install the dev dependencies with composer

$ composer install

Run the unit tests suite with atoum binary

$ vendor/bin/atoum -bf vendor/autoload.php -d Tests/Unit/

Run functional tests with behat binary using the Symfony2 fixture application

$ vendor/bin/behat -c