Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grails - subdomain based projects and links

I am trying to develop a grails application that has "root" content (www.mydomain.com/about for example) but will also support "projects" based upon the subdomain of the request; for example myproject.mydomain.com > www.mydomain.com/myproject. As a first pass, i have the URL configuration below:

"/$controller/$action?/$id?" {
 ...
}

"/$project/$controller/$action?/$id?" {
    constraints {
    }
}

The main drawback so far is that the $project variable must be injected manually into every link (tedious and not DRY):

<g:link controller="foo" action="bar" params="${[project: params.project]}">link</g:link>

Is there a way to automatically inject the $project parameter into all links if it is present, or is there a better way to approach this problem?

like image 908
Rich Kroll Avatar asked Nov 14 '22 14:11

Rich Kroll


1 Answers

Basically you can create a grails plugin that will inject into the controller a new project param with a value based on a custom TagLib <g:project bean="myproject"/> (for instance)

It will force you to define this tagLib on each gsp page of your project but it is still DRYer than each link.

Hope it helps,

Fabien.

like image 87
fabien7474 Avatar answered Jan 11 '23 02:01

fabien7474