You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to use markup templates to render html views instead of using gsp pages. When playing a little bit with templates I came up with an example.
Controller providing some model objects
Markup view rendered using a custom layout which requires a linkGenerator to resolve resources such as css stylesheets and declaring model objects to use
The same view is including some other templates that require linkGenerator to create links
Controller
packageorg.protoclassSomethingController {
staticclassPerson {
Long id
String name
Integer age
}
defindex() {
render(
view: 'index',
model: [
totalCount: 10,
people: [
newPerson(id: 1, name: 'John', age: 32),
newPerson(id: 2, name: 'Peter', age: 34)
]
]
)
}
}
views/something/index.gml
Declaring model objects in here makes them available to included templates which is the expected behavior. Although I'm not creating any link here, I've checked that it's possible to use Link generator here (via this.g.link and this.g.resource).
importorg.proto.SomethingController
model {
Integer totalCount
List<SomethingController.Person> people
}
layout 'layouts/custom.gml', title: 'Layout example', bodyContents: contents {
p "Showing $totalCount rows"
table {
include(template: 'something/_thead.gml')
include(template: 'something/_tbody.gml')
}
}
views/layouts/custom.gml (fails)
However here, calls to this.g.resource fail because linkGenerator is null.
Versions
Context
I would like to use markup templates to render html views instead of using gsp pages. When playing a little bit with templates I came up with an example.
Controller
views/something/index.gml
Declaring model objects in here makes them available to included templates which is the expected behavior. Although I'm not creating any link here, I've checked that it's possible to use Link generator here (via this.g.link and this.g.resource).
views/layouts/custom.gml (fails)
However here, calls to this.g.resource fail because linkGenerator is null.
views/something/_thead.gml
Obviously works as expected because it doesn't use anything special
views/something/_tbody.gml (fails)
As it happened to custom.gml calls to this.g.link didn't work either because linkGenerator is null.
Problem
My first impression is that although you can access to the link generator at the top level view, you can't in any of the included, nested templates.
Desired behavior
To be capable of accessing main view link generator from any nested/included templates.
The text was updated successfully, but these errors were encountered: