<?php
namespace Core;
use \Michelf\Markdown;

class View
{
    private static $twig = null;

    public static function render($template, $args = [])
    {
        if (self::$twig === null) {
            $loader = new \Twig_Loader_Filesystem('../App/Views');
            self::$twig = new \Twig_Environment($loader);

            $filtermd = new \Twig_Filter('rendermd', function($string) {
                return Markdown::defaultTransform($string);
            }, ['is_safe' => ['html']]);

            self::$twig->addFilter($filtermd);
        }

        echo self::$twig->render($template, $args);
    }
}
