link directly to GSP
Solution 1
The createLink tag is geared for use with controller actions and won't do what you want it to outside of the url attribute.
You can always get to a gsp by directly: /user/foo.gsp
with a combination of the link and resource tags.
<g:link url="${resource(dir:'user', file:'foo.gsp')}">user/foo.gsp</g:link>
Othewise you can create a URL Mapping that maps a request directly to a view.
class UrlMappings {
static mappings = {
"/user/foo"(view:"user/foo")
}
}
Using Grails 1.2 you can create a named URL Mapping that maps directly to a view:
class UrlMappings {
static mappings = {
name userFoo: "/user/foo"(view:"user/foo")
}
}
and then use it with the link tag:
<link:userFoo>User Foo</link:userFoo>
or
<g:link mapping="userFoo">User Foo</g:link>
Solution 2
There's a uri attribute that's undocumented , but you can see it in the source:
<a href="${createLink(uri:'/path/page.gsp')}">link</a>
HTH
Related videos on Youtube
Dónal
I earn a living by editing text files. I can be contacted at: [email protected] You can find out about all the different kinds of text files I've edited at: My StackOverflow Careers profile
Updated on December 08, 2020Comments
-
Dónal over 3 years
In a GSP, is it possible to create a direct link to another GSP? I know I can use:
<g:createLink controller="user" action="foo"/>
and in UserController define the foo action to just show the corresponding GSP
class UserController { def foo = {} }
But is there any way I can achieve the same result without having to create the empty
foo
action?Thanks, Don
-
Pravin over 9 yearsHey Dave, what should the path be? I tried "/views/p.gsp " and "grails-app/views/p.gsp" Neither worked.
-
Gabe M over 9 yearsRemove the /views/ out of your path, just do p# instead of p.gsp and it should resolve.