Exclude javascript from email template

Using SilverStripe 4.12

I have a ContactPage and it has an AJAX form on there that sends emails. In my ContactPage_Controller I have the email template generated like this:

$emailBody =  $this->customise([
    			'Layout' => $this->customise($templateData)->renderWith(['MyModule\Layout\Contact_Email'])])->renderWith(['Email']);

However, because ContactPage_Controller has a javascript requirement, it includes this javascript reference in the email html source which is very bad regarding anti-spam filters.

protected function init() {





I’m a bit clueless as to exclude the script from the email template rendering.

Well, a couple of choices…

  1. Use the setHTMLTemplate() method on the Email class, and set the body up that way rather than generating it through the controller
  2. Generate your body HTML using SSViewer instead of the controller (but option 1 is really the ‘normal’ way)
  3. Move the Requirements call out of the init() method, and into the index() method on your controller (assuming you don’t have a lot of different actions defined in the controller)