New in Statie 4.5: Twig Support

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 and Twig.

Statie supports YAML and Symfony Dependency Injection for some time. But you wanted more! You wanted Twig. Sculpin and all the other PHP Static Website generators have it.

So there you go! Enjoy

See pull-request

3 Steps to Your First Page on Statie

1. Prepare Layout _layouts/default.twig

<!DOCTYPE html>
<html lang="en">
    {% include "_snippets/head.twig" %}
        {% include "_snippets/menu.twig" %}

            {% block content %}{% endblock %}

        {% include "_snippets/footer.twig" %}

2. Create Template contact.twig

layout: "_layouts/default.twig"

{% block content %}
    <h1>Call me</h1>

    <a href="tel:+420776778332">+420 <strong>776 778 332</strong></a>
{% endblock %}

And you're ready to go!

How to Upgrade to Statie 4.5?

Update it in composer:

composer require symplify/statie 4.5

And try:

vendor/bin/source generate

It will probably fail because there was one change in templating reference.

Before the paths of included files were just a file name and the full path was guessed. This practice is common in Nette and Symfony Controllers, so I used as a starting point. But it caused many WTFs and name conflicts like:

{% include "detail" %}

Which file will is used? Or is it a block import? Magic :)

How to do it better with a principle of the least surprise?

Clear, Obvious File Naming

All files in _layouts and _snippets are now referenced by they full relative path to source (usually /source directory):

-layout: "default"
+layout: "_layouts/default.twig"

-{% include "postMetadata" %}
+{% include "_snippets/postMetadata.twig" %}

Do you use Generators? Don't forget to upgrade them too:

-            layout: 'post'
+            layout: '_layouts/post.twig'

Already Running on Statie 4.5

Check diffs of these merged pull-requests so you have the idea how small the change really is:

How to Migrate Latte to Twig as Well?

If you use Statie, you're probably running on Latte. In the case you prefer Twig, I guess you're already frustrated from annoying Latte to Twig migration you have ahead of you.

Again, check these diffs, so you have the idea how big that change really is:

I feel you. You can stay with Latte until... just kidding. That's a lot of work, right? Well, I'm not that hardworking, don't worry. I'm a lazy bastard, so I made a package for Latte to Twig migration.


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

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