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

80 views Asked by At

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

2

There are 2 answers

1
Mike W On BEST ANSWER

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>
0
Mario On

I think Mike's answer is correct, and although I do not know the context of your project I think it might in the long run be better to add a class dynamically to the element.

Something like

<div class="myClass ${extraClass}">...</div>