I have a custom module with a controller where I'm building a PDF file with a node's data that will be mailed to a certain user.
I have installed the SwiftMailer module and I have been able to produce my desired outcome, but it isn't very clean.
I was wondering if I could use a twig
template to build the body of my HTML email. Is there anyway I can make use of Drupal's Twig Extension for this purpose?
I already created a email.html.twig
file with the layout I need and I already have a $parameters
array with all the variables I need to use in the template, but as SwiftMailer uses an HTML string in the setBody()
method, I'm trying to use Twig to produce the HTML I need to use there. Any thoughts?
Please note that I don't want to use the twig template in my module ( to show a Drupal page or something), but rather have Twig render an HTML string I can use with SwiftMailer. Also, the instructions for the SwiftMailer module regarding theming are rather confusing for me and they are for Drupal 7, so I don't see how I can make use of them in my case.
Any help would be very welcome!