I found a DIRTY (but working) way to render complex gsps offline using groovyPageRenderer with a replaced script source. In this case, you have access to the entire gsp syntax, including g:if , etc.
First define two dummy classes:
class StringPageLocator extends GrailsConventionGroovyPageLocator { GroovyPageScriptSource findViewByPath(String content) { return new StringScriptSource(content) } } class StringScriptSource implements GroovyPageScriptSource{ String content public StringScriptSource(String content) { this.content=content } @Override String suggestedClassName() { "DummyName" } @Override boolean isPublic() { true } @Override String getScriptAsString() { return content } @Override boolean isModified() { true } @Override String getURI() { "DummyURI" } }
And then you can use it as such:
def groovyPageLocator // Injected automaticaly to service/controller etc... groovyPageRenderer.groovyPageLocator=new StringPageLocator() String output=groovyPageRenderer.render( view:'Hello2 ${user} <g:if test="${test}">TRUE!!!</g:if>', model:[user:'test user2',test:true]
)
source share