Plugins You can find out about all the publicly available Grails plugins.

Grails Template Engine

  • Tags: templating
  • Latest: 0.2.1
  • Last Updated: 13 February 2012
  • Grails version: 1.1 > *
  • Authors: Peter Delahunty
3 votes
compile ":grails-template-engine:0.2.1"



This plugin exposes the GSP engine as a service. It allows you use the gsp template engine to render gsp out side the standard response.


grails install-plugin grails-template-engine


Grails Template Engine Plugin

This plugin is probably only useful to Grails applications < 2.0.0. Applications using more a more recent version of Grails should use the
introduced in Grails 2.0.0 and/or the
tag instead of this plugin


The Grails Template Engine simply exposes the GSP rendering engine as a service. The need for this arose when i wanted to generate an example php file for my customers but wanted to use the GSP engine to create the page.


The plugin is currently compatible with version 1.1 of grails. Not tried it on an earlier version.


Installation is very simple as is all grails plugin installations;

grails install-plugin grails-template-engine


To use the plugin is very simple.

Include the Service

class DemoService {

def grailsTemplateEngineService

def myServiceMethod = {

String text = grailsTemplateEngineService.renderView("/demo/phpFile", [message:"hello"])

// do something with the text



Controller convenient method

I also added a convenient method to the controllers called renderWithTemplateEngine

def fileDownload = {

String text = renderWithTemplateEngine("/demo/phpFile", [message:"hello"])

response.contentLength = text.size() response.contentType = 'text/plain' response.setHeader("Content-disposition", "attachment; filename=sample.php") response.outputStream << text.bytes response.outputStream.flush() }

The GSP is nothing special

Hello <?php echo urlencode($_GET['name']); ?>

Message: ${message}

Important notes

Make sure you do not set response.contentType to 'text/html' as it will get picked up by the grails standard render engine and will try to encode your file.


  • 0.2 - GrailsTemplateEngineService line 45 controllerName should be pluginName. Resolved in version 0.2.1