views:

22

answers:

1

Hi, I tried to bind data to a template created using GroovyPagesTemplateEngine, but cannot. Here is what I can as far I can go. Could some one help? Thanks!

import org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine
import org.springframework.core.io.FileSystemResource

File myfile = new File("c:\\myTools\\mydata.gsp")
def engine = new GroovyPagesTemplateEngine()

def data = ['data':'test']       

def template = engine.createTemplate(new FileSystemResource(myfile))

I tried template.make(data), but does not work.....

A: 

Try this:

import groovy.text.SimpleTemplateEngine

def engine = new SimpleTemplateEngine()
String templateContent = new File('c:/myTools/mydata.gsp').text
def binding = [data: 'test']

String rendered = engine.createTemplate(templateContent).make(binding).toString()
Burt Beckwith
Yes, that works. However, when I tried to use taglibs. I cannot access them. I thought I could use GroovyPagesTemplateEngine to solve my problem. Do you know how to access taglibs using SimpleTemplateEnine? thank you!!!
john