How do I use a Twig template to generate Email content from inside a plugin I'm making? I'm trying to do a nicely formatted email from a plugin I'm making. The standard way I've been doing simple emails is all entirely in the code, somewhat like this:

$notificationEmail = new EmailModel();
$notificationEmail -&gt; toEmail  = $userEmail;
$notificationEmail -&gt; subject  = "Subject here";
$notificationEmail -&gt; body     = "Thanks $userName, you’re now registered on our website.";
$notificationEmail -&gt; htmlBody = " ... MASSIVE COMPLICATED STUFF THATS FAR BETTER SUITED TO TWIG ... "
craft()-&gt;email-&gt;sendEmail($notificationEmail);


I've now got an email that is far better suited to being generated via a Twig template because I'm going to have to loop through relational fields and all sorts. I have no idea how and I don't seem to know what to Google to get what I'm after... Anyone got pointers to this sort of thing?
Thanks to Brad for providing the bulk of the answer. In more detail the line needing to be changed was this:

$notificationEmail -&gt; htmlBody = craft()-&gt;templates-&gt;render('PLUGIN-FOLDER-NAME/TEMPLATE-NAME', ['theUser' =&gt; $user]);


I could then use {{ theUser }} (Which is a UserModel) in the TEMPLATE-NAME template to generate everything I needed.

So the full solution, to send an Email from a plugin, but using a Twig template to generate the HTML email content was:

$myEmail             = new EmailModel();
$myEmail -&gt; toEmail  = $user-&gt;email;
$myEmail -&gt; subject  = "Subject here";
$myEmail -&gt; body     = "PLAIN TEXT CONTENT";
$myEmail -&gt; htmlBody = craft()-&gt;templates-&gt;render('PLUGIN-FOLDER-NAME/TEMPLATE-NAME', ['theUser' =&gt; $user]);
craft()-&gt;email-&gt;sendEmail($myEmail);


Where $user was a variable containing a UserModel which I'd already got from previous code in the plugin I was writing.

https://craftcms.com/classreference/services/TemplatesService#render-detail for more detail (but for which I wish there were example code of how to use, and not just a dictionary).