Skip to main content

Hello addItEasy 0.1.0!

This blog post might be outdated!
This blog post was published more than one year ago and might be outdated!
· 3 min read
Stephan Hochdörfer
Head of IT Business Operations

I was looking for a way to show how our libraries like Adrenaline, Pathfinder and Disco work in a "real world" application. I came up with the idea to build just another simple flat-file CMS. AddItEasy might be the first flat-file CMS based on a PSR-7 implementation which adds a nice touch: We can easily create a static file export from the content. That means that you do not need to upload addItEasy to your server, you can simply export the files and e.g. let GitHub host the static HTML pages.

To install addItEasy use Composer:

composer.phar require bitexpert/additeasy

To initialize a new project use the built-in cli tool:

./vendor/bin/addItEasy init

This creates a bunch of directories and folders:

 |-assets
|-cache
|-config
|-content
|-export
|-template
|-vendor

Find the project specific configuration in config/config.inc.php, the default version looks like this:

$EASY_CONF = [];

// addITeasy configuration
$EASY_CONF["app"] = [];
$EASY_CONF["app"]["cachedir"] = __DIR__ . "/../cache";
$EASY_CONF["app"]["assetdir"] = __DIR__ . "/../assets";
$EASY_CONF["app"]["logfile"] = $EASY_CONF["app"]["cachedir"] . "/easy.log";
$EASY_CONF["app"]["datadir"] = __DIR__ . "/../content";
$EASY_CONF["app"]["templatedir"] = __DIR__ . "/../template/";
$EASY_CONF["app"]["exportdir"] = __DIR__ . "/../export";
$EASY_CONF["app"]["defaultpage"] = "";

// Site configuration (these vars get passed to the twig template)
$EASY_CONF["site"][] = "";
$EASY_CONF["site"]["title"] = "addITeasy Demosite";
$EASY_CONF["site"]["baseurl"] = "http://localhost:8080/";

You are able to configure the cache directory, the asset directory, the data directory containing the content files and the template directory. Variables defined in $EASY_CONF["site"] will be passed as is to Twig which is used as templating engine. Access those variables like this: site.title or site.baseurl.

Templates need the placed in the template folder, a template could look like this:

<html lang="en">
<head>
<title>{{ site.title }}</title>
<base href="{{ site.baseurl }}" />
</head>
<body>

<!-- Content block -->
{% block content %}
{% endblock %}

</body>
</html>

Content files are also twig templates and need to be placed in the content folder. The content files need to extend a template and provide all the needed blocks a template requires.

{% extends "default.twig" %}

{% block content %}
<div>
Hello World!
</div>
{% endblock content %}

Every page of your site is represented by a subfolder in the content directory. The folder names build the URL structure for your site, nested subfolders are allowed. Each folder needs to be prefixed with a number which is used to indicate the sorting order. Each folder needs to contain one twig template file containing the content to display. The content folder could look like this:

 |-01-home
|---home.twig
|-02-about
|---about.twig
|-posts
|---01-post1
|-----post1.twig
|---02-post2
|-----post2.twig
|---03-post3
|-----post3.twig
|---04-post4
|-----post4.twig

In case you want to run addItEasy locally the following command needs to be executed in the project directory:

php -S 0.0.0.0:8080 -t .

Open a web browser and point it to http://localhost:8080 so see addItEasy in action. In case you want to export the content as static HTML files run the following command:

./vendor/bin/addItEasy export

This will export all pages into the directory defined in $EASY_CONF["app"]["exportdir"] as well as copying all the assets.