Pico CMS

Pico is a flat file cms with a well thought through plugin system to extend its capabilities.

It's fast, it's light-weight and perfect for small websites.

Sessions und Twig

See session plugin and access via template vars: x

public function onPageRendering(Twig_Environment &$twig, array &$twigVariables, &$templateName)
{
    $twig->addGlobal('session', $_SESSION);
    //d($_SESSION,$twigVariables,$twig);
}

{{ session.username }}

Include Template Fragment in Page

Render twig template fragments in markdown page

# Wiki

This is my digital garden[^1]

{% include 'wiki-posts.twig' %}

[^1]: <https://tomcritchlow.com/2019/02/17/building-digital-garden/>
<!-- wiki-posts.twig -->
<section id="blog-listing">
    {% for page in pages if not page.hidden %}
    {#{ dump(page.meta) }#}
    <article class="postx">
        <header class="post-header">{{page.Status}}
            <h2 class="post-title">
                <a href="{{ page.url }}" up-dash=".main" up-transition="cross-fade">{{ page.title }}</a> →
            </h2>
        </header>
    </article>
    {% endfor %}
</section>
<?php

class TweakOutput extends AbstractPicoPlugin
{
    const API_VERSION = 2;

    protected $enabled = true;

    public function onPageRendering(&$templateName, array &$twigVariables)
    {
        preg_match('/\<p>{%\s+include\s+\'([a-z-]+\.twig)\'\s+%\}<\/p>/m', $twigVariables['content'], $matches);
        if(!$matches) return;
        $html = $this->getTwig()->render($matches[1], $twigVariables);
        $twigVariables['content'] = str_replace($matches[0],$html, $twigVariables['content']);
    }
}

Render External Data from an API with Inline Twig Templates

Read about it here

Table of Content in Pages

https://github.com/caseyamcl/toc

# GIS, Geolocation

[ TOC]

Links to location related stuff.

## Linklist

- bla

## More
<?php

class TweakOutput extends AbstractPicoPlugin
{
    const API_VERSION = 2;

    protected $enabled = true;

    public function onContentParsed(&$content)
    {
        $markupFixer  = new TOC\MarkupFixer();
        $tocGenerator = new TOC\TocGenerator();

        $content = $markupFixer->fix($content);
        $toc = '<div class="toc">' . $tocGenerator->getHtmlMenu($content, 1,2) . '</div>';

        if(strpos($content,'[ TOC]') !== false)
        {
            $content = str_replace(['<p>[ TOC]</p>','[ TOC]'], $toc, $content);
        }
    }
}