g:include vs g:render
NickName:rascio Ask DateTime:2012-06-14T22:07:04

g:include vs g:render

I have a question about pros and cons of g:render and g:include. In my application I have a piece of code that shows some information that have to be repeated in some gsp, what it show depends on a little bit of logic.
I have a doubt is it better use a g:include or a g:render???
So, is it better to execute the logic on a controller that pass a model to the page that use a layout included with the g:render, or is better to put a g:include to another action in another controller in the gsp that execute the logic of that piece?
I prefer the second choice, but how much it impact on the performance?

Copyright Notice:Content Author:「rascio」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/11034869/ginclude-vs-grender

Answers
chrislatimer 2012-06-14T20:15:48

They are just used in different cases. You use <g:include .../> when you have a controller that is returning a piece of content that is easily embedded in multiple GSPs. This is also useful if you have a high volume of traffic where you are actually caching at the controller level since you can eliminate a lot of overhead.\n\n<g:render.../> is useful when you need modularity within your page. Especially for AJAX calls where you may initially load one portion of the page then want to update it based on some AJAX event. \n\nBoth can be used to reuse content, and both are appropriate in the right context.",


More about “g:include vs g:render” related questions

g:include vs g:render

I have a question about pros and cons of g:render and g:include. In my application I have a piece of code that shows some information that have to be repeated in some gsp, what it show depends on a

Show Detail

Grails and PermGen issue with g:link and g:render

I've been running grails for sometime without any issues but recently after an upgrade to Grails 1.1.1, I've encountered the dreaded PermGen errors. Prior to the upgrade, no such issue. The error ...

Show Detail

How to use g:render in g:select for optionValue?

I have a g:select statement that looks like the following: &lt;g:select id="gearbox" name="gearbox.id" from="${com.nppc.mes.energyusage.Gearbox.list()}" optionKey="id" optionValue="${ {"${it.g

Show Detail

The difference between render(...) and g.render(...) in grails

I have the following bit in a controller: def myJSON = [ 'form' : g.render(template: '/information/form', model:informationInstance) ] ren...

Show Detail

trying to use g include tag under 3.1.10

Trying to use g:include on a grails 3.1.10 app and it seems: This appears to pass id through ok &lt;g:include action=&quot;show&quot; id=&quot;${currentBook.id}&quot; /&gt; Trying to pass params o...

Show Detail

How to detect that a controller has been called by g:include tag lib?

In order to send appropriate response, I need to detect whether the controller action has been requested by a classic HTTP GET request, an AJAX request or a g:include tag lib. For instance, consid...

Show Detail

Grails g:render a template (or render a div) onClick event

I am creating a hierarchical list with expandable/ collapsible list items. When a user clicks on a list item to expand it a table pops up with some info. Right now, grails is rendering all of the t...

Show Detail

Grails: g:render pass data

I'm having problems to pass data through g:render to another view, which is included in printme.gsp printme.gsp: &lt;h1&gt;abc&lt;/h1&gt; ${input1Instance?.number} &lt;!-- Here I can see the right

Show Detail

Render g.select on controller

How to i set the default value on g:select from controller? From my list of name's for example here's my list ["peter","josh","john","thomas"] render g.select( name:'selectName'

Show Detail

Using g.render in a grails service

I'm trying to use g.render in a grails service, but it appears that g is not provided to services by default. Is there a way to get the templating engine to render a view in the service? I may be...

Show Detail