Customizing Results for Entities

How results are returned from the search is important. Luckily, there are numerous ways to customize the results from the search. We cover all the options below.

Default Entity Results

Each entity has a default result template that you can change. This is a great place to modify what you'd like to be returned across multiple search interfaces. You can edit these templates on a per-entity basis under Admin Tools > Security > Entity Administration.

There are two templates available for your customization. The first, Index Results Template, is the template for the result row of the search. The other, Index Document URL Pattern, is the Lava template for determining the URL for the specific result when used in the Smart Search.

Entity Configuration

Let's consider a use case for how you might want to modify these templates. Say you have a custom group type in Rock that you would like to display differently than the normal group result. Perhaps you'd like to add a specific attribute value for the group and link to a different group detail page. This is all possible by updating these two Lava templates.

Sample Results Template

{% assign url = "~/Group/" | ResolveRockUrl %}

{% assign groupTypeId = IndexDocument.GroupTypeId %}
{% if groupTypeId == 24 %}
    {% assign url = "~/Organization/" | ResolveRockUrl %}
{% endif %}

{% if DisplayOptions.Group-Url and DisplayOptions.Group-Url != null and DisplayOptions.Group-Url != '' %}
    {% assign url = DisplayOptions.Group-Url | ResolveRockUrl %}
{% endif %}

<div class="row model-cannavigate" data-href="{{ url }}/{{ IndexDocument.Id }}">
    <div class="col-sm-1 text-center">
        <i class="{{ IndexDocument.IconCssClass }} fa-2x"></i>
    </div>
    {% if groupTypeId == 24 %}
        <div class="col-sm-4">
            <strong>{{ IndexDocument.Name }}</strong> <small>({{ IndexDocument.GroupTypeName }})</small>
            {% if IndexDocument.Description != null and IndexDocument.Description != '' %}
                <br> 
                {{ IndexDocument.Description }}
            {% endif %}
        </div>
        <div class="col-sm-7">
            {{ IndexDocument.MemberList }}
        </div>
    {% else %}
        <div class="col-sm-11">
            <strong>{{ IndexDocument.Name }}</strong> <small>({{ IndexDocument.GroupTypeName }})</small>
            {% if IndexDocument.Description != null and IndexDocument.Description != '' %}
                <br> 
                {{ IndexDocument.Description }}
            {% endif %}
        </div>
    {% endif %}
</div>

Notice the checking of the group type to customize the URL and the results.

Sample URL Template

{% assign url = "~/Group/" | ResolveRockUrl %}

{% assign groupTypeId = IndexDocument.GroupTypeId %}
{% if groupTypeId == 24 %}
    {% assign url = "~/Organization/" | ResolveRockUrl %}
{% endif %}

{% if DisplayOptions.Group-Url and DisplayOptions.Group-Url != null and DisplayOptions.Group-Url != ' %}
    {% assign url = DisplayOptions.Group-Url | ResolveRockUrl %}
{% endif %}

{{ url }}/{{ IndexDocument.Id }}

Custom Lava

When using the default search block, you can process your results through custom Lava you produce. This Lava is provided as a block setting. You'll need to both enable the usage of the custom Lava and provide a Lava template. A very basic template is provided as a starting point.

Search Results

Search Lava Command

When you want 100% control, you can drop down and use the "search" Lava command. This command works very similarly to the entity commands and allows you 100% control of the formatting of your results. See the documentation for this command in the Lava docs at community.rockrms.com/lava.