Rendering templates in services

If you want to render gsp template on level of service (or in any other bean), just get org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib bean from spring context, and call method render on it:

 
class FooService {
 
    boolean transactional = false
 
    def grailsApplication
 
    def bar(view, model) {
        render(template:"/templates/emails/${view}", model:model)
    }
 
    private def render(args){
        grailsApplication.mainContext.getBean('org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib').render(args)
    }
}
 

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.