Groovy-Grails Crib Sheet


  • Use either of the following two options to display a date:
    • <g:formatDate format="yyyy"/>
    • ${new Date().format("yyyy")}
  • Use either of the following two to create a link (relative to the application’s root):
    In the cases below, link creates a full anchor (<a>) tag/element, whilc createLink only returns/prints the URL/href/src.
    • <g:link uri="/blah/" class="css-class">Link</g:link>
    • <a href="${createLink(uri:'/blah/')}" class="css-class">Link</a>
    • <a href="${link(uri:'/blah/')}" class="css-class">Link</a>
    • createLink is used to create a URL. <g:createLink/> is the markup-flavored way to do the same: ${createLink(controller:'hello',action:'world',,params:[key1:'value1',key2:'value2'])} and <g:createLink controller="application" action="archive" id="${}" params="[key1: 'value1', key2: 'value2']" /> would both resolve to something like this: /hello/world/1?key1=value1&key2=value2
    • link and <g:link/> are correlary, and are used for building out an entire anchor tag (standard hyperlink).
    • RAW - ${raw('test')} - you get the idea! - h/t Tony


If you need to change the version of Grails to a different one that you have previously downloaded (using SDKMAN), you can issue the following command in the terminal:

$ sdk use grails 2.3.11