grailsgrails-3.1

<g:set> variable's value is not being rendered properly


I've used <g:set> tag like this:

<g:set var="extraStyle" value="style='min-width:120px;'"/>

and used the extraStyle variable like this:

<div class="myClass" ${extraStyle}> ${myValue}</div>

And it should be rendered as:

<div class="myClass" style="min-width:120px;"> XYZ </div>

But, I am getting this instead:

<div class="myClass" style="'min-width:120px;'"> XYZ </div>

Due to which, min-width style is not being applied. What am I doing wrong here?

Grails version: 3.1.6


Solution

  • You could try just setting the style value e.g.

    <g:set var="extraStyle" value="min-width:120px;"/>
    
    <div class="myClass" style="${extraStyle}"> ${myValue}</div>