Last updated by admin 3 years ago
grails install-plugin grails-template-engine
Last updated by domurtag 3 months ago
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
Overview
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.
Compatibility
The plugin is currently compatible with version 1.1 of grails. Not tried it on an earlier version.
Installation
Installation is very simple as is all grails plugin installations;
grails install-plugin grails-template-engine
Documentation
To use the plugin is very simple.
Include the Service
class DemoService {def grailsTemplateEngineServicedef 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.
Bugs
- 0.2 - GrailsTemplateEngineService line 45 controllerName should be pluginName. Resolved in version 0.2.1
Last updated by burtbeckwith 2 years ago
Last updated by admin 3 years ago