xpico
May 15, 2019, 11:05am
1
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:
If($this->view->exist('mytemplate.html')){
return $this->view->render($response, 'mytemplate.html', $data);
}else{
return $this->view->render($response, '404.html');
}
Thanks,
Antnee
May 15, 2019, 11:31am
2
_i_g
May 16, 2019, 2:43pm
3
You might have to do something like this:
$view->getLoader()->exists(’@your /path)
I ended up customising slim/twig for this reason
1 Like
xpico
May 16, 2019, 3:20pm
4
ok, thank @_i_g , that works for me.
Stjo
May 20, 2019, 10:01am
5
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
See the official docs (they are pretty great at this)
http://www.slimframework.com/docs/v3/handlers/not-found.html
xpico
May 20, 2019, 6:56pm
6
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…