Search code examples
grailsgsp

Understanding the purpose of the underscore in grails templates


Working with grails templates and the render method isn't that hard. I worked with it for a while now.

It's okay for me to deal with the 'Convention over Configuration'. And so it is with the needed underscore "_" at the beginning of the filename of a template .gsp file.

I'm not that experienced with programming in general, I'm doing an apprenticeship as a 'IT-specialist for application development' since 2,5 years now. So my background knowledge isn't that big yet.

But I'd now really like to understand what exactly the purpose of that underscore is. How's grails dealing with files with a leading underscore in comparison to those without it?


Solution

  • String view='/path/to/file'
    def model= [template:view,instance:bean]
    render(view:view, model:model)
    

    this tells that template is '/path/to/_file.gsp' when it renders the template bit

    when it renders view it looks for '/path/to/file.gsp'

    so when you do render view it looks for files without underscore when you do render template it looks for those with underscore

    above example does both to explain how it works