2

I couldn't find this anywhere else, I'm looking up if the currentUser.isInGroup('verified') and if not, display another link. Works fine when logged in but throws a Template and Runtime error when using the {{logoutUrl}} or viewing any page when not logged in.

I expected this would work the same as currentUser by itself, which throws no errors. But obviously there's something I'm missing. Should I be using something like craft.session in combination with the isInGroup? Or some other method of detection?

enter image description here enter image description here

Update

{% if currentUser.isInGroup('verified') is defined %}

Seems to get rid of the errors. So a couple of questions:

  • Is this expected behaviour?
Rob
  • 865
  • 6
  • 13

1 Answers1

1

Yes, that's expected behavior. currentUser will not exist if there is not a currently logged in user.

{% if currentUser.isInGroup('verified') is defined %}

That's one workaround for it.

Another would be:

{%if currentUser is defined and currentUser.isInGroup('verified') %}

which to me reads a little better even though it's more verbose.

Brad Bell
  • 67,440
  • 6
  • 73
  • 143