PatrickLouys / no-framework-tutorial

A small tutorial to show how to create a PHP application without a framework.
MIT License
1.53k stars 186 forks source link

Switching from Mustache Renderer to Twig Renderer #71

Closed tylerlazenby closed 4 years ago

tylerlazenby commented 4 years ago

I have been stuck on this one for a while. I cannot for the life of me figure out how to do this I am at the step where you would switch the renderer alias from Mustache_Engine to Twig. here is my code

/**
 * Mustache Renderer
 */
/*$injector->alias('Todo\Template\Renderer', 'Todo\Template\MustacheRenderer');
$injector->define('Mustache_Engine', [
    ':options' => [
        'loader' => new Mustache_Loader_FilesystemLoader(dirname(__DIR__) . '/templates', [
            'extension' => '.html',
        ]),
    ],
]);*/

/**
 * Twig Environment
 */
$injector->alias('Todo\Template\Renderer', 'Todo\Template\TwigRenderer');
$injector->delegate('Twig_Environment', function () use ($injector) {
    $loader = new Twig_Loader_Filesystem(dirname(__DIR__) . '/templates');
    return new Twig_Environment($loader);
});

But All I get is the following error

LogicException
You must set a loader first.
tylerlazenby commented 4 years ago

Somebody was kind enough to give us this.

https://stackoverflow.com/questions/60234016/switching-injector-alias-from-mustache-engine-to-twig/60498772#60498772