What are we building?

This recipe will show you how to add a panel to the person profile that will show a list of all the groups that you follow with an indicator to show if the person being viewed is in any of those groups.

bookmarked_groups-pannel.jpg

I can make a badge to show "In Group", why would I need this?

If you were to make a badge for every group a staff member could want to see at a glance, you will end up with a lot of badges. Also, not all staff members would care about the same groups.

The idea was to replicate the functionality of the "Bookmarked Attributes" panel on the profile page. This will allow your staff to choose the groups that they want to see at a glance, without having to go to the groups tab and scroll through a long list.

How?

  • Add a HTML Block to the person profile page.
  • Edit the block settings
    • Check the box for "Enabled Lava Commands" > "RockEntity"
    • Select "Person" from the dropdown under "Context > Entity Type"
  • Set the Block's content to the following:
//- Find all of the groups I am following
{% following where:'EntityTypeId == 16' expression:'PersonAlias.PersonId == {{ CurrentPerson.Id }}' securityenabled:'false' %}
    {% assign groupIds = followingItems | Select:'EntityId' %}
{% endfollowing %}

//- Go through the list of groups from above and lookup the data for each group
{% capture results %}
[
    {% for groupId in groupIds %}
        {% assign group = groupId | GroupById %}
        {% if group %}
            {
                'Id': {{ group.Id | ToJSON }},
                'Name': {{ group.Name | ToJSON }},
//- Is the person in the group?
                'Member': {{ group.Members | Select:'PersonId' | Contains:Context.Person.Id | ToJSON }}
            },
        {% endif %}
    {% endfor %}
]
{% endcapture %}
{% assign results = results | FromJSON %}

//- Sort the list
{% assign results = results | Sort:'Name' %}

//- Format the display table
<div class='panel panel-persondetails'>
    <div class='panel-heading'>
        <h3 class='panel-title pull-left'><i class='fa fa-bookmark'></i> Bookmarked Groups</h3> 
    </div>
    <div class='grid grid-panel'>
        <table class='table table-hover'>
            <tr>
                <th style='padding-left:24px'>Group Name</th>
                <th>Is Member</th>
            </tr>
            {% for group in results %}
                <tr onclick='window.location.href="/people/groups?GroupId={{ group.Id }}"' style='cursor:pointer'>
                    <td style='padding-left:24px'>{{ group.Name }}</td>
                    <td>{% if group.Member %}<i class='fa fa-check'></i>{% endif %}</td>
                </tr>
            {% endfor %}
        </table>
    </div>         
</div>

Change Log

  • 2022-02-11 - Initial Version
  • 2022-03-19 - Updated Lava to be v12 compatible