Search code examples
phptwigslim-3

Get twig file content and pass variables


I'm planning to create a function that sends an email but my concern is that I need to get my email template and pass variables inside.

For now this is what I got :

$template = $this->view->render('./partials/email-template.twig',['name'=>'sample']);

but I'm getting this error :

Uncaught TypeError: Argument 1 passed to Slim\Views\Twig::render() must implement interface Psr\Http\Message\ResponseInterface, string given, called in C:\xampp\htdocs\master\app\Controllers\Admin\VoucherController.php on line 34


Solution

  • According to this thread you would need to use fetch first, e.g.

    $template = $this->view->fetch('./partials/email-template.twig');
    $html = $template->render(['name' => 'sample', ]);