Implement default layout with configuration in grails

Posted By : Shiv Kumar | 30-Sep-2014

When we set up a new grails project, grails provide us a default layout(main.gsp) in views > layouts > main.gsp.

This layout is implemented on the required page by using meta tag like :

<meta name="layout" content="main"/>

If we have lots of pages and using the same line of code on each required page becomes cumbersome.

Here is a better way to avoid such situation by configuring it in config.groovy.

Yes grails provides an easiest way to configure default layout so that meta tag is not used on each page. By doing this, main.gsp layout will be available on each page. 

 

All you have to do is make this configuration in config.groovy :

grails.sitemesh.default.layout = 'main'

Advance Approach :

If you don't even want to define this configuration in config.groovy and want to include layout on your gsp view, smart grails is here for you.

Just rename your main.gsp to application.gsp and run the project with clean.

 

Grails will automatically provide the layout on each view page without using any meta tag or configuration.

 

Thanks

Shiv Kumar

About Author

Author Image
Shiv Kumar

Shiv is an experienced Java Developer with a strong background in multiple technologies. He specializes in defining system architectures to ensure reliable and resilient solutions. He possesses a comprehensive understanding of the latest technologies and has hands-on experience in Core Java, Spring Boot, Hibernate, Apache Kafka messaging queue, Redis, as well as relational databases like MySQL and PostgreSQL, and non-relational databases like MongoDB. He excels in API implementations, Microservices, Web Services development, testing, and deployments. Shiv actively contributes to code enhancements and consistently delivers valuable contributions to various client projects, including Fabtrack, Pando, Pandojo, Digikam, WhatsApp Integration, Croniz, Punchin Application, Script TV, Bhaasha, and more. He demonstrates strong analytical skills and a creative mindset. In addition, he has a passion for reading books and exploring new technologies and innovations.

Request for Proposal

Name is required

Comment is required

Sending message..