New in Symplify 3: Statie Generators

Found a typo? Edit me
This post is deprecated since March 2020. Its knowledge is old and should not be used.

Statie was deprecated with last version 7, because 99 % of features are covered in Symfony application.

To create static content, migrate to Symfony app and SymfonyStaticDumper.

This post was updated at September 2018 with fresh know-how.
What is new?

Updated with Statie 5, NEON → YAML, Twig and statie.yml config.

Statie missed one important feature. Posts were the only elements that you could render as standlone page. But what if you want a web porfolio, not with posts but with features projects? Or lectures pages?

Statie 3 to the rescue!

Coupled Approach in old Statie

Posts in Statie 2 were enabled by defaults with following hard coded logic:

You could change a post_route or layout in specific post file, but that was it. No flexibility, no extendability and modification of PostFile class was not possible.

In we're staring community lectures and we need not only posts, but also lectures to be on stand-alone page, e.g.

If this could be only configurable, it would benefit many websites that are more than just a list of posts.

Configurable Approach in Statie 3 with Generators

So here comes Statie 3 Generators. Same posts approach is now set by default, but also configurable in parameters > generators section:

        posts: # key useful for exception reports
            # name of variable inside single such item
            variable: post
            # name of variable that contains all items
            varbiale_global: posts
            # directory, where to look for them
            path: '_posts'
            # which layout to use
            layout: '_layouts/post.twig'
            # and url prefix, e.g. /blog/
            route_prefix: 'blog'
            # an object that will wrap it's logic, you can add helper methods into it and use it in templates
            object: 'Symplify\Statie\Renderable\File\PostFile'

The whole old posts logic is now configurable.

Do you need to change path to _articles?

            path: '_articles'

Or do you want to use own simpler object?

            object: 'MyWebsite\Statie\SimplePostFile'

How to Add Own Generator?

So how did we solved lectures in website?

Adding new Generator Element is now easy:

# statie.yml
            variable: 'lecture'
            variable_global: 'lectures'
            path: '_lectures'
            layout: '_layouts/lecture.twig'
            route_prefix: 'kurz'
            object: 'Pehapkari\Website\Statie\Generator\LectureFile'

Do you want real code? See this commit that has it all.

The configuration is as simple as possible, so object is optional. You can read how to set own file in documentation.

How to add new Lecture?

  1. Create new *.md file in source/_lectures/ directory
  2. Have _layout/lecture.twig ready
  3. Create LectureFile with extra getTitle() method

That's all!

These lectures will be available in every template under {$lectures} variable, as configured in variable_global option.

So you can create page source/all-lectures.twig with all lectures (ordered by filename):

{% for lecture in lectures %}
    <h2>{{ lecture.getTitle() }}</h2>
{% endfor %}

Try Generators Out

Just upgrade Statie:

composer update symplify/statie

and add lectures, talks with details, docs... anything you need.

Date Me!

One more surprise to prevent. In case you use route_prefix with date in it:

# statie.yaml
            route_prefix: 'blog/:year/:month/:day'

remember, the date has to be in start of the filename:


When setup properly, you get this file in generated code:


How to Upgrade from Statie 2 to Statie 3?

"Real code is worth of thousand words describing it."
Anonymous Lazy Programmer

See these PRs:

Happy Generating!

Have you find this post useful? Do you want more?

Follow me on Twitter, RSS or support me on GitHub Sponsors.