Login required
Download

FreeMarker Grails Plugin

(1)
Author(s): Jeff Brown
Current Release: 0.2
Grails Version: 1.1 > *
Tags scaffolding templating

Introduction

The Grails FreeMarker plugin provides support for rendering FreeMarker templates as views.

Getting Started

Installing The FreeMarker Plugin

Install the FreeMarker plugin with the install-plugin command:

grails install-plugin freemarker

Rendering FreeMarker Templates

The FreeMarker plugin supports rendering FreeMarker templates as views. FreeMarker templates should be defined below the views/ directory in the same places where you might define GSP views. For example, if you have a controller named DemoController that looks like this:

class DemoController {

def index = { [name: 'Jeff Beck', instrument: 'Guitar'] }

}

Then you could define a FreeMarker template in grails-app/views/demo/index.ftl that looks like this:

<html>
<body>
  Name: ${name} <br/>
  Instrument: ${instrument}<br/>
</body>
</html>

FreeMarker Tag Library

The FreeMarker plugin contributes a tag called render which is defined in the fm namespace. The tag works much like the render tag that is bundled with grails except that it renders FreeMarker templates instead of GSPs. The template supports the template and model attributes and may be used from any GSP. The following example shows the tag being used from a GSP.

<html>
<body>
  <fm:render template="myFreeMarkerTemplate" model="[name: 'Jake']"/>
</body>
</html>

More Information

For more information on FreeMarker templates see the FreeMarker site.