Grabbing Symfony TWIG template output as a string to use in string-based HTML bodies such as email templates, etc.

Amazing, but this solution is so simple and it is no where on Stack Overflow. There’s a lot more documentation about rendering templates from a string but not TO a string, something very helpful if you want to use templating to build html output for things like email templates.

$output=$this->render('view.html.twig', array(
  'form' => $form->createView(),
  'info' => $info,
  ‘otherVals’ => $otherVals,
  ‘someArray’=> $someArray
));

var_dump($output->getContent()); exit;

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

Your email address will not be published. Required fields are marked *