File tree Expand file tree Collapse file tree 2 files changed +19
-8
lines changed
java/org/codehaus/groovy/grails/plugins/web/taglib
test/org/codehaus/groovy/grails/web/taglib Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -478,8 +478,9 @@ class RenderTagLib implements com.opensymphony.module.sitemesh.RequestConstants
478478 if (t== null ) {
479479 def contextPath = attrs. contextPath ? attrs. contextPath : null
480480
481- if (attrs. plugin) {
482- contextPath = pluginManager?. getPluginPath(attrs. plugin) ?: ' '
481+ def pluginName = attrs. plugin
482+ if (pluginName) {
483+ contextPath = pluginManager?. getPluginPath(pluginName) ?: ' '
483484 }
484485 else if (contextPath == null ) {
485486 if (uri. startsWith(" /plugins/" )) contextPath = " "
@@ -488,14 +489,21 @@ class RenderTagLib implements com.opensymphony.module.sitemesh.RequestConstants
488489 }
489490 }
490491 def templatePath = " ${ contextPath}${ uri} "
492+ def templateResolveOrder
493+ if (pluginName) {
494+ templateResolveOrder = [templatePath, " ${ contextPath} /grails-app/views/${ uri} " ]
495+ }
496+ else {
497+ templateResolveOrder = [uri, templatePath, " ${ contextPath} /grails-app/views/${ uri} " ]
498+ }
491499
492- t = engine. createTemplateForUri([templatePath, " ${ contextPath } /grails-app/views/ ${ uri } " ] as String [])
493- if (! engine. isReloadEnabled() && t!= null ) {
500+ t = engine. createTemplateForUri(templateResolveOrder as String [])
501+ if (! engine. isReloadEnabled() && t!= null ) {
494502 def prevt = TEMPLATE_CACHE . putIfAbsent(uri, t)
495503 if (prevt != null ) {
496504 t = prevt
497505 }
498- }
506+ }
499507 }
500508
501509 if (! t) {
Original file line number Diff line number Diff line change @@ -98,19 +98,22 @@ class RenderTagLibTests extends AbstractGrailsTagTests {
9898
9999 resourceLoader. registerMockResource(' /foo/book/_book.gsp' , ' foo ${foo}: ${body()}' )
100100 resourceLoader. registerMockResource(" /plugins/controllers-${ GrailsUtil.grailsVersion} /foo/book/_book.gsp" . toString(), ' plugin foo ${foo}: ${body()}' )
101+ resourceLoader. registerMockResource(" /plugins/controllers-${ GrailsUtil.grailsVersion} /foo/book/_two.gsp" . toString(), ' plugin foo ${foo}: ${body()}' )
101102
102103
103104 template = ' <g:render plugin="controllers" template="/foo/book/book" model="[foo: \' bar\' ]">hello</g:render>'
104105 assertOutputEquals ' plugin foo bar: hello' , template
105106
106107 template = ' <g:render contextPath="" template="/foo/book/book" model="[foo: \' bar\' ]">hello</g:render>'
107108
109+ assertOutputEquals ' foo bar: hello' , template
110+
108111 request. setAttribute(GrailsApplicationAttributes . PAGE_SCOPE , new GroovyPageBinding (" /plugins/controllers-${ GrailsUtil.grailsVersion} " ))
109- assertOutputEquals ' plugin foo bar: hello' , template
112+ assertOutputEquals ' foo bar: hello' , template // application template should be able to override plugin template
113+ template = ' <g:render contextPath="" template="/foo/book/two" model="[foo: \' bar\' ]">hello</g:render>'
110114
115+ assertOutputEquals ' plugin foo bar: hello' , template // should resolve to plugin template
111116 request. removeAttribute GrailsApplicationAttributes . PAGE_SCOPE
112-
113- assertOutputEquals ' foo bar: hello' , template
114117 }
115118
116119 void testRenderTagWithBody () {
You can’t perform that action at this time.
0 commit comments