grails / grails-gsp

GSP (Grails Server Pages) - A server-side view rendering technology based on Groovy
Apache License 2.0
15 stars 32 forks source link

Allow optional attribute for g.render that will ignore if tag if template does not exist. #495

Closed codeconsole closed 1 month ago

codeconsole commented 1 month ago

Very useful for scaffolding where you could use the same scaffold gsp across multiple controls and produce different behavior. Without the optional attribute the default behavior persists and an exception is thrown.

<g:render template="optionalTemplate" optional="true" />

For instance: /src/main/templates/show.gsp

            <section class="row">
                <div id="show-${propertyName}" class="col-12 content scaffold-show" role="main">
                    <g:render template="/includes/admin/title"/>
                    <g:render template="/includes/admin/filter">
                        <g:render optional="true" template="/${propertyName}/includes/show/main"/>
                    </g:render>
                    <f:display bean="${propertyName}" class="container" listItemClass="row mb-3" labelClass="form-label col-sm-3 text-sm-end" valueClass="col-sm-9" />
                    <g:render template="/includes/admin/actions" model="\${[domain:${propertyName}]}">
                        <g:render optional="true" template="/${propertyName}/includes/show/menu"/>
                    </g:render>
                </div>
            </section>
matrei commented 1 month ago

This should probably not have been merged to 6.2.x as it is a new feature. I missed that in my review.

codeconsole commented 1 month ago

@matrei idk, I don't consider this a "new feature". Any existing usages produce exactly the same content as before. if the standard was to do a new minor release every time an attribute or variable was changed, Spring Boot would be on version 10,000 by now. We need to adopt a Spring Boot versioning model. Especially considering we do not have the resources to maintain multiple minor releases.

matrei commented 1 month ago

@codeconsole I don't think Spring Boot introduce new features or change public API in patch releases. Prove me wrong 😉

codeconsole commented 1 month ago

@matrei this is a "bug fix". Change the title to "g.render should not always throw and exception when a template does not exist" :P