我試圖在我的控制器範圍之外呈現模板。在Grails 2.x中未找到名稱和路徑的模板
,我想呈現模板位於景色的/ home/index.gsp中的觀點
編輯:
我嘗試呈現模板 「_list-clients.gsp」和「_list-hubs.gsp」,均位於/視圖/模板中我主要佈局「main.gsp」位於/視圖通過使用我invok標籤庫E在一個視圖「的list.gsp」位於/視圖/客戶
Here's如何我包括內容標籤的視圖:
<g:pageProperty name="page.client-menu"/>
在這裏,我調用在標籤庫內容標籤中的list.gsp:
<content tag="client-menu">
<g:createClientMenu ></g:createClientMenu>
</content>
這裏是我的taglib:
package com.pmedia.taglib
import com.pmedia.domain.Company
class CreateClientMenuTagLib {
def createClientMenu = { attrs, body ->
def company = Company.findByName("pMediaNetwork")
out << '<ul>'
out << '<li class="dropdown">'
out << '<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">'
out << 'Select Hub or Client for ' + company?.name
out << '<b class="caret"></b>'
out << '</a>'
out << '<ul class="dropdown-menu pull-right">'
if (company?.getHubs()) {
out << render(template:"/templates/list-hubs", collection: company.getHubs(), var:"hubs")
}
if (company?.getClients()) {
out << render(template:"/templates/list-clients", collection: company.getClients(), var:"clients")
}
out << '</ul>'
out << '</li>'
out << '</ul>'
}
}
模板位於視圖/模板/ _list-hubs.gsp
我不斷收到此錯誤:
URI
/newLayout/home/index
Class
org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException
Message
Template not found for name [templates/list-hubs] and path [/home/templates/_list-hubs.gsp]
我預想的Grails開始尋找在查看文件夾時,我帶領的URL一個「/」但由於某些原因模板無法找到。
有人知道如何解決這個問題嗎?
代碼和錯誤似乎沒有關係。您的渲染代碼使用模板'/ templates/list-hubs',而您的錯誤消息是針對模板'templates/list-clients'。您已經忘記了**客戶**模板的主要斜線。 – hsan 2013-03-11 16:28:35
對不起,當發佈錯誤時,我沒有重新加載瀏覽器。我在上面編輯了它的實際錯誤。 – bernheart 2013-03-11 16:38:21
仍然看起來好像你缺少主導斜線。另外,你是否在scriptlet塊('<% ...%>')中調用'render'?這是[灰心](http://grails.org/doc/latest/guide/theWebLayer.html#GSPBasics)。爲什麼不使用''標籤(或[模板名稱空間](http://grails.org/doc/latest/guide/theWebLayer.html#viewsAndTemplates))? –
hsan
2013-03-11 16:57:02