Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to externalize GSP mail templates with Grails?

When emails are rendered from templates, the templates are looked up in "grails_app/views":

mailService.sendMail {
    from sender
    to recepient.email
    subject "Don't forget"
    body  (view: "/emails/reminder",
        model:[recepient: recepient, document: document])
}

How can I put the mail templates outside of the application (war file) into the file system?

like image 738
deamon Avatar asked Jan 19 '11 14:01

deamon


1 Answers

There are two options:

  1. Store your templates as text in the database, and generate the default crud code to update them. You would then modify the email code to pull the data out of the database using domain objects.
  2. Store the templates as strings in a Groovy config file. Groovy can use external configuration files that can be edited separately from the packaged application. See this blog postfor details.

Once you have your string, you can use the GSP engine from a Grails controller with any arbitrary string to create a view. See this blog post for more details.

In short, you would store your template as a string using one of the listed options and then use the Grails GSP engine to create the view once you retrieved the template string.

like image 119
Jared Avatar answered Sep 27 '22 21:09

Jared