Answer the question
In order to leave comments, you need to log in
How to catch an Exception thrown in a twig custom function?
//botstrup.php
$twig->addFunction(new Twig_SimpleFunction('generateSchoolList', function($class){
if(!class_exists($class))
throw new \NotFoundClassException($class);
echo (new $class)->sendOutput();
}));
//controller
class Controller{
function index(){
try{
return $this->twig->render("home");
} catch(\Exception $e){
return $e->getMessage();
}
}
}
//home.twig
<td>{{generateModule('Project\\UserList') }}</td>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question