I am trying to create a conditional taglib in grails to determine whether or not to display a user Avatar (I based the code on the ifLoggedIn tags found here: http://www.grails.org/AuthTagLib )
My taglib looks like this:
def ifProfileAvatar = {attrs, body ->
def username = session.user.login
def currentUser = Account.findByLogin(username)
if (currentUser.profile && currentUser.profile.avatar) {
out << "avatar found"
body{}
}
}
And in my GSP I use the tag like this:
<g:ifProfileAvatar>
<br/>profile found!<br/>
</g:ifProfileAvatar>
When I navigate to the GSP, "avatar found" is being displayed correctly (directly from the taglib) but "profile found!" is not.
Is there any reason that the body{} in the taglib is not showing the body in the GSP?
Any ideas where it might be going wrong?
Thanks!
Wrong sort of braces after body, I think it should be:
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 {}
}
}
See this page in the documentation for more examples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With