Grails - Does a template exist?

I’ve recently finished an internal taglib that allows us some awesome extended scaffolding. I may try to turn it into a full-fledged plugin/project, but for now, here’s a few tips for the ether:

First, to return errors from a taglib, you can simply call a function called “throwTagError”. I didn’t see that documented a lot of places.

Second, to see if a gsp template exists, you can do something like this inside a taglib:

def fullUri = grailsAttributes.getTemplateUri(template, request)
def resource = grailsAttributes.pagesTemplateEngine.getResourceForUri(fullUri)

if ( resource && resource.file && resource.exists() )
    // good template
else
    // bad template

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment