rhi*_*nds 3 grails groovy taglib
我试图在grails中创建一个条件标记库,以确定是否显示用户头像(我基于ifLoggedIn标签上的代码:http://www.grails.org/AuthTagLib)
我的taglib看起来像这样:
def ifProfileAvatar = {attrs, body ->
def username = session.user.login
def currentUser = Account.findByLogin(username)
if (currentUser.profile && currentUser.profile.avatar) {
out << "avatar found"
body{}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的GSP中,我使用这样的标签:
<g:ifProfileAvatar>
<br/>profile found!<br/>
</g:ifProfileAvatar>
Run Code Online (Sandbox Code Playgroud)
当我导航到GSP时,"avatar found"正在正确显示(直接来自taglib),但"找到了个人资料!" 不是.
是否有任何理由说明body{}taglib没有在GSP中显示身体?
任何可能出错的想法?
谢谢!
tim*_*tes 10
之后错误的括号body,我认为它应该是:
def ifProfileAvatar = {attrs, body ->
def username = session.user.login
def currentUser = Account.findByLogin(username)
if (currentUser.profile && currentUser.profile.avatar) {
out << "avatar found"
out << body() // Use () not {}
}
}
Run Code Online (Sandbox Code Playgroud)
有关更多示例,请参阅文档中的此页面