Maxim K.
Maxim K.

Reputation: 651

g:set tag inside template body in grails

I using <g:set> tag inside g:render template body

<g:render template="/template/panelContainer">
  <g:set var="tomorrow" value="${new Date() + 1}"/>
  ${tomorrow}
</g:render>

_panelContainer.gsp:

<div class="panel panel-default">
${raw(body())}
</div>

However tomorrow variable is not set. How do I need to implement template to properly execute g:set tag?

Upvotes: 2

Views: 443

Answers (2)

Chetan
Chetan

Reputation: 1707

First of all you need to set the variable before calling the render method.

<g:set var="tomorrow" value="${new Date() + 1}"/>

Then you can pass this variable in your template using the model attribute. Like:

<g:render template="/template/panelContainer" model="${[tomorrow:tomorrow]}"/>

The body() you are trying to use is used to pass along other body content to be displayed inside the template. Like:

<g:render template="/template/panelContainer" model="${[tomorrow:tomorrow]}">
  <a href="..">..</a>
</g:render>

Upvotes: 2

ABC
ABC

Reputation: 4373

Try this :

<g:set var="tomorrow" value="${new Date() + 1}"/>
<g:render template="/template/panelContainer" model="${[tomorrow:tomorrow]}"/>

Upvotes: 1

Related Questions