Search code examples
grailsgsp

Grails: GSP variable substitution in g:each tag


I have a loop inside a loop and want to substitute the value of first var into second. Below is the code snippet.

<g:each in="${tables}" status="i" var="table">
    <div class="tabletitle">
        ${table.name}
    </div>
    <table>
        <thead>
            <tr>
            <g:each in="${${table.name}DisplayColumns}" status="k" var="displayColumn">
                <td>${displayColumn}</td>
            </g:each>
            </tr>
        </thead>
        <tbody>
            ....
            ....
        </tbody>
    </table>
</g:each>

${table.name} substitution in second g:each tag is not working. Any idea to make it work?


Solution

  • Try this:

        <g:each in="${evaluate(table.name+'DisplayColumns')}" status="k" var="displayColumn">