/** * Produce a preview of the mailing content. * * @return null|string */ public function generatePreview() { $this->updateTemplateVarsWithContact($this->getContactService()->getContact()); if (is_null($this->mailing)) { throw new \RuntimeException("The mailing object is empty. Did set the template"); } try { return $this->renderer->render($this->mailing->getTemplate()->getTemplate(), array_merge_recursive(['content' => $this->personaliseMessage($this->email->getMessage())], $this->templateVars)); } catch (\Twig_Error_Syntax $e) { print sprintf("Something went wrong. Error message: %s", $e->getMessage()); } return true; }