Search code examples
grailstemplate-enginegspsitemesh

Are there any workarounds for Grails sitemesh not supporting if statements with open HTML body tags


I have a GSP with the below code..

 <g:if test="${'Ethan Hunt'.equals(agentName)}">
 <body>
       Secret Mission
 </g:if>
        Unclassified stuff
  </body>

Right now this gives an exception..

org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException:         
Grails tag [sitemesh:captureBody] was not closed

According to this, such usage is not supported in Grails using sitemesh for layouts and the only workaround is to set sitemesh.preprocess config to false.

But that post is fairly old so I was wondering if there are any better workarounds now?

Of course an obvious one would be to re-factor the code to move the if check inside the body but supposing that was not an option (this sample is a simplification of my actual code where this refactor option would not work).

Are there any other options to avoid this exception but still keep this code?


Solution

  • There are no better workarounds other than refactoring the code or turning off pre-processing (which impacts performance quite a lot).

    Not much has changed with both Sitemesh and Grails use of Sitemesh since then.