Reputation: 4338
Imagine you layout page of your grails application has some dynamic content that gets update on each page request. When a page is requested, the controller that is requested has nothing to do with the dynamic data provided by the main.gsp page. How should I manage this?
I mean when a page is requested, how do I update the dynamic portion of the layout portion that the page controller is agnostic about? Plus I do not want to put layout dynamic code is every controller.
Upvotes: 1
Views: 515
Reputation: 3709
You might be able create a TagLib for this.
grails create-tag-lib myLayout
Then make your taglib responsible for the remote service calls. You can do pretty much anything in a taglib that you can to in a controller, and you can also call any Grails services you've already created.
class MyLayoutTagLib {
static namespace = "myLayout"
def stockQuoteService
def getStockPrice = { attrs ->
out << stockQuoteService.getLatestPrice(attrs.stockSymbol)
}
}
Then in your gsp
<myLayout:getStockPrice stockSymbol="${user.favoriteStockSymbol}" />
Or however you get the relevant data to make the remote service call.
Upvotes: 1