How to render a view from service class in symfony?

Viewed 1659

I'm trying to make a function in my service class, that render a twig page. I've tried to do like this: service.yml:

********
parameters:
    error.class: AppBundle\Utils\Error
services:
    app.error:
        class: '%error.class%'
        arguments: [@templating]

Error.php (service class):

****
class Error
{
    public function __construct($templating)
    {
        $this->templating = $templating;
    }

    public function redirectToError($condition,$message)
    {
        if($condition){
            return $this->templating->render('default/error.html.twig',array(
                'error_message' => $message,
            ));
        }
    }

}

and error.html.twig that have some random text to see if it gets there.

After that I get this answer from browser:

enter image description here

Can somebody to tell me what is the problem?

2 Answers
Related