1

I'm trying to show a menu based on what group a user is in once they have logged in. However, I'm not having any success. Here is an example (for one of the groups) of what I have in my _base.html file, which I'm extending in my other pages:

{% if currentUser.isInGroup('advisors') %}
    <div class="secondary-navigation">
        <div class="row">
            <div class="small-1 columns group">
                <h2>Advisors</h2>
            </div>
            <div class="small-11 columns navigation">
                <ul>
                    <li><a href="">Advisors Home</a></li>
                    <li><a href="">Education</a></li>
                    <li><a href="">Blog</a></li>
                    <li><a href="">Events</a></li>
                    <li><a href="">Nav 5</a></li>
                </ul>
            </div>
        </div>
    </div>
{% endif %}

Any suggestions would be most welcome!

4
  • That looks reasonable to me. What is it doing wrong? Jan 9 '17 at 20:31
  • It's not displaying the menu when I log in as a "client" user (or one of the others that I've got set up.
    – Todd
    Jan 9 '17 at 21:48
  • 1
    So you log in as a client, which is in the advisors group, but that piece of the nav doesn't get displayed? Do you have devMode on? Jan 9 '17 at 22:11
  • No. I'm a Craft noob, and wasn't aware of that. I will enable it and do some more testing. Thanks!
    – Todd
    Jan 9 '17 at 22:18
1

OK, so enabling the devMode helped point me in the right direction.

First, I needed to change it to

{% if currentUser and currentUser.isInGroup('advisors') %}

Otherwise I was getting an error message when nobody was logged in ("Impossible to invoke a method ("isInGroup") on a null variable").

Then I discovered that the user I was testing wasn't added to any groups! I could have sworn I set up the user with a group assigned, but apparently not. :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.