Twig-View: Twig doesn't show anything

I’m using the twig view helper and it does not show anything… There is no error, nothing, just a blank white page. The server says “200”… I don’t know what I’m doing wrong.

For example if I use the php-view package or simply do $response->getBody()->write("foo") it works. But with the twig-view it doesn’t work.

app/
    cache/
    templates/
        home.twig
    src/
        App.php
        Twig.php
        Home.php
        ...
public/index.php
vendor/
...

I have my own App class, which holds an object of Slim\App. Here I create an object of my own Twig class, which executes this code:

$container = $app->getContainer();
$container["view"] = function ($container) {
    $view = new Slim\Views\Twig("../app/templates", [
        "cache" => "../app/cache"
    ]);

    $view->addExtension(new Slim\Views\TwigExtension(
        $container["router"],
        $container["request"]->getUri()
    ));

    return $view;
};

And instantiate an object of the Home class, with this code:

$app->get("/", function ($request, $response, $args) {
    return $this->view->render($response, "home.twig", []);
});

My template home.twig contains just <h1>Hello world!</h1>.

Can someone help me? Or do you need more information?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

@givanov2 you should be setting the cache to false

    $view = new \Slim\Views\Twig('path/to/templates', [
        'cache' => false
    ]);

You can try to disable cache , maybe error message be show $view = new Slim\Views\Twig("../app/templates");