Search code examples
grails

How to set layout and views to specific controller in grails


In simple the Grails application, I have created the controller and the corresponding GSP view page. I have also created the layout file and I want to bind it to the view. How to do it?

Thanks in advance


Solution

  • You need to direct the corresponding view to use it. You can do this by adding the following to your view's html-head:

    <meta name="layout" content="$yourlayout" />
    

    Or by adding this to your controller class:

    static layout = '$yourlayout'
    

    In both ways, substitute $yourlayout with the name of your layout file (without the .gsp-extension).

    There are also other ways to trigger a layout e.g. by convention, you can find all of them in the Grails user guide.