Last updated by admin 2 years ago
Last updated by daniel_henrique 9 months ago
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>
Troubleshooting
Per
http://jira.codehaus.org/browse/GRAILS-6221, in applications with more than one view resolver, UrlMappings.groovy may need to be updated. . When adding this plugin to an existing grails project that also uses .gsp by default
the "/" mapping will be indeterminate. Fix by setting "/"(view:"/index.gsp") or "/"(view:"/index.ftl") if that is what you want to use.
More Information
For more information on FreeMarker see
the FreeMarker site.
Release Notes
Version 0.3
- Upgrade to FreeMarker 2.3.16
- Improve access to flash scope in a FreeMarker template
Version 0.4
- GPFREEMARKER-11 fix
- Adding FreemarkerViewService and FreemarkerTemplateService
- Packages renamed
Last updated by admin 2 years ago
Last updated by admin 2 years ago