Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7604971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:02:58+00:00 2026-05-31T00:02:58+00:00

I have an application that uses the grails multi-tenant-core plug-in to host multiple versions

  • 0

I have an application that uses the grails multi-tenant-core plug-in to host multiple versions of a site. I want to be able to create custom GSPs for each site beyond what simple skinning will allow me to do. Essentially, I want to be able to have my grails-app/views folder look something like:

views
|
|__template1
|  |
|  |__layouts
|  |  |
|  |  |__main.gsp
|  |  
|  |__controller1
|     |    
|     |__index.gsp
|
|__template 2
   |
   |__layouts
   |  |
   |  |__main.gsp
   |  
   |__controller1
      |    
      |__index.gsp

And then configure a specific tenant to use a specific set of GSPs. I am using a DNS resolver that’s persisted in my database, so I could presumably add a property to the DomainTenantMap domain class that assigns a templateDir property to a particular tenant and sprinkle conditional logic all over the place in my GSPs and controllers. (followed by that ‘can’t…get…clean’ feeling)

I haven’t had any success finding an existing plug-in that provides this functionality. The other options I have considered seem to involve customizing fairly core pieces of grails (render tag, template engine, etc.) which makes me nervous.

I realize this is a fairly broad question; both specific solutions and general suggestions are appreciated.

EDIT:

I found another possible approach by creating a plug-in and meta-programming on a new method:

def configureTemplateRenderer(application, applicationContext) {
    for (controllerClass in application.controllerClasses) {

        controllerClass.metaClass.newRender = { args ->
            println 'something'
            if(args.view) {
                args.view = "/somedir/${args.view}"
            }
            if(args.template) {
                args.template = "/somedir/${args.template}"
            }
            delegate.render(args)
        }
    }
}

This is just a proof of concept to see if I can invoke the standard render method through my new one (I can). Ideally, I could override the render method entirely to modify the args.view and args.template property based on some sort of tenant/template mapping (not shown). However, I haven’t been able to override the render method successfully so this solution is really only marginally better than just sprinkling in some path variable to calls to render.

A Solution!

I ended up creating a separate plug-in that essentially boils down to overriding the render method with one that checks a tenant/template map. Still testing but so far it looks promising, here’s the gist of it:

def overrideRender = { application ->
    for (controllerClass in application.controllerClasses) {
        def original = controllerClass.metaClass.getMetaMethod("render", [Map] as Class[])
        def originalRender = original.getClosure()

        controllerClass.metaClass.originalRender = originalRender

        controllerClass.metaClass.render = { Map atts ->
            def templatePath = // some code to lookup against a TenantTenantMap
            if(templatePath) {
                if(atts.view) {
                    atts.view = "${templatePath}${atts?.view}"
                }
                if(atts.template) {
                    atts.template = "${templatePath}${atts?.template}"
                }
            }
            delegate.originalRender(atts)
        }
    }
}

The only downside is that I have to use a slightly uglier directory structure than I wanted: views/controller/$template/action instead of combining all the template gsps together under views/$template/controller/action. I think I can live with that for now.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:02:59+00:00Added an answer on May 31, 2026 at 12:02 am

    The solution I used:

    def overrideRender = { application ->
        for (controllerClass in application.controllerClasses) {
            def original = controllerClass.metaClass.getMetaMethod("render", [Map] as Class[])
            def originalRender = original.getClosure()
    
            controllerClass.metaClass.originalRender = originalRender
    
            controllerClass.metaClass.render = { Map atts ->
                def templatePath = // some code to lookup against a TenantTenantMap
                if(templatePath) {
                    if(atts.view) {
                        atts.view = "${templatePath}${atts?.view}"
                    }
                    if(atts.template) {
                        atts.template = "${templatePath}${atts?.template}"
                    }
                }
                delegate.originalRender(atts)
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a grails application that uses spring-security-core and spring-security-ldap, with authentication against Active
I have an existing grails application that uses spring-security plugin for authentication. I would
I have a Grails application that uses ThreadLocal. Currently ThreadLocal populating and clearing is
I have an application that uses fms and i want to upload to windows
I have an application that uses NHibernate as its ORM and sometimes it experiences
I have client application that uses WCF service to insert some data to backend
I have an application that uses the accelerometer. Sometimes, the application will launch without
I have an application that uses window.open() to generate dynamic popups. Unfortunately, I've had
I have an application that uses a cron like job to update a set
We have an application that uses a dual monitor setup - User A will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.