[solved] Check if template exists before rendering

Hi all,

I’m using slim with slim/twig-view. Anyone know if is there a way to check if template exists before calling to render?
Something like:

    return $this->view->render($response, 'mytemplate.html', $data);
    return $this->view->render($response, '404.html');



You might have to do something like this:

I ended up customising slim/twig for this reason

1 Like

ok, thank @_i_g , that works for me.

You don’t mention what Slim version you are using? So I will assume its Slim3!?

If that’s the case, there’s actually a handler for this :slight_smile:

See the official docs (they are pretty great at this)


Thank for the answer @Stjo, but that’s not my case. In my case i need to check if template exist inside one route. The route exist but i don’t know if template exist. It’s not usually case but…