Lava Additions

In order to prevent naming collisions in the future, all Lava filters provided by this plug-in are prefixed with BBM_ to ensure uniqueness. Below you can find all the filters that are made available once this plug-in has been installed.

Array Filters

BBM_AddToArray

Add a new item to an existing array, also will create a new array if null or '' is used as the source array. While the examples use simple strings, you can add anything to an array - even entity objects such as a Group or Person.

Example

"Items": [
    "one"
]
{% assign array = Items | BBM_AddToArray:'two' | BBM_AddToArray:'three' %}
<ul>
{% for item in array %}
    <li>{{ item }}</li>
{% endfor %}
</ul>
<ul>
    <li>one</li>
    <li>two</li>
    <li>three</li>
</ul>

BBM_Distinct

Takes an array as input and returns the distinct (unique) elements of the array.

Example

"Items": [
    "hello",
    "test",
    "one",
    "hello",
    "two",
    "one",
    "three"
]
{% assign array = Items | BBM_Distinct %}
<ul>
{% for item in array %}
    <li>{{ item }}</li>
{% endfor %}
</ul>
<ul>
    <li>hello</li>
    <li>test</li>
    <li>one</li>
    <li>two</li>
    <li>three</li>
</ul>

BBM_GroupBy

Takes a collection of items and groups them by the specified property tree value. The returned data is a dictionary. Each distinct property tree value is represented as a key in the dictionary with all associated original objects as values of that key. As such, when iterating through the result you need to use the PropertyToKeyValue filter to get the key and the array of values.

Example

"Members": [
    {
        "GroupRole": {
            "Name": "Member"
        },
        "Person": {
            "FirstName": "Alex"
        }
    },
    {
        "GroupRole": {
            "Name": "Leader"
        },
        "Person": {
            "FirstName": "Ted"
        }
    },
    {
        "GroupRole": {
            "Name": "Member"
        },
        "Person": {
            "FirstName": "Cindy"
        }
    }
]
{% assign groupedmembers = Members | BBM_GroupBy:'GroupRole.Name' %}
<ul>
{% for group in groupedMembers %}
    {% assign parts = group | PropertyToKeyValue %}
    <li>{{ parts.Key }}</li>
    <ul>
        {% for member in parts.Value %}
            <li>{{ member.Person.FirstName }}</li>
        {% endfor %}
    </ul>
{% endfor %}
</ul>
<ul>
    <li>Leader</li>
    <ul>
        <li>Ted</li>
    </ul>
    <li>Member</li>
    <ul>
        <li>Alex</li>
        <li>Cindy</li>
    </ul>
</ul>

BBM_OrderBy

Orders a collection of elements by the specified property tree and returns a new collection in that order.

You can sort by multiple keys, for example you can sort by LastName and then by FirstName at once. Each key to sort by is separated by a comma (,) character. Each sorted property can change the default order from ascending (default) to descending by appending a space and desc to the property name.

For example, if you specify the order by property of FirstName desc then the collection will be sorted by FirstName and the results will be returned in descending order.

Example

"Members": [
    {
        "GroupRole": {
            "Name": "Member",
            "IsLeader": false
        },
        "Person": {
            "FirstName": "Alex"
        }
    },
    {
        "GroupRole": {
            "Name": "Leader",
            "IsLeader": true
        },
        "Person": {
            "FirstName": "Ted"
        }
    },
    {
        "GroupRole": {
            "Name": "Member",
            "IsLeader": false
        },
        "Person": {
            "FirstName": "Cindy"
        }
    }
]
{% assign members = Members | BBM_OrderBy:'GroupRole.IsLeader desc,Person.FirstName' %}
<ul>
{% for member in members %}
    <li>{{ member.Person.FirstName }} - {{ member.GroupRole.Name }}</li>
{% endfor %}
</ul>
<ul>
    <li>Ted - Leader</li>
    <li>Alex - Member</li>
    <li>Cindy - Member</li>
</ul>

BBM_RemoveFromArray

Take a collection of objects and return a new collection which does not contain the specified value.

Example

"Items": [
    "one",
    "two",
    "three"
]
{% assign array = Items | BBM_RemoveFromArray:'two' %}
<ul>
{% for item in array %}
    <li>{{ item }}</li>
{% endfor %}
</ul>
<ul>
    <li>one</li>
    <li>three</li>
</ul>

Dictionary Filters

BBM_AddToDictionary

Takes an existing (or empty) dictionary and returns a new dictionary with the added key and value. Can pass null or '' to initialize a new dictionary.

Example

"Object": {
    "Id": 23,
    "FirstName": "Ted"
}
{% assign data = Object | BBM_AddToDictionary:'CalculatedValue',89 %}
{{ data | ToJSON }}
{
    "Id": 23,
    "FirstName": "Ted",
    "CalculatedValue": 89
}

BBM_AllKeysFromDictionary

Retrieves all keys that exist in the dictionary object and returns them in an array.

Example

"Object": {
    "Id": 23,
    "FirstName": "Ted",
    "LastName": "Decker"
}
{% assign keys = Object | BBM_AllKeysFromDictionary %}
<ul>
    {% for key in keys %}
    <li>{{ key }}</li>
</ul>
<ul>
    <li>Id</li>
    <li>FirstName</li>
    <li>LastName</li>
</ul>

BBM_RemoveFromDictionary

Removes the specified key from a dictionary of keys and values.

Example

"Object": {
    "Id": 23,
    "FirstName": "Ted",
    "LastName": "Decker"
}
{% assign data = Object | BBM_RemoveFromDictionary:'FirstName' %}
{{ data | ToJSON }}
{
    "Id": 23,
    "LastName": "Decker"
}

Miscellaneous

BBM_AddHttpHeader

Adds a header to the HTTP Response of the current web request.

Example

{{ 'Content-Type: text/plain' | BBM_AddHttpHeader }}

BBM_Function

Calls a function that was previously defined with the bbm_function command. The function to be called is the first parameter and any extra parameters are passed on to the function itself.

Function calls can be recursive, so you can call a single method from within itself. This can be useful when you want to build a list-item tree of groups.

Example

{% bbm_function Demo salutation %}
Hello salutation Input
{% endbbm_function %}

{{ CurrentPerson.LastName | BBM_Function:'Demo','Mr.' }}
Hello Mr. Decker

BBM_RunLava

Executes Lava that is inside a string. Very useful when taking Lava from an Attribute Value and wanting to process it to display it to the user. The Lava executes in the same security context as the existing Lava. So if you have Entity Commands enabled in your parent Lava then the child Lava you execute will also be able to run Entity Commands.

Example

{
    "Value": "{% assign test = 'Hello World' %}{{ test }}"
}
<p>
    {{ Value }}
</p>
<p>
    {{ Value | BBM_RunLava }}
</p>
<p>
    {% assign test = 'Hello World' %}{{ test }}
</p>
<p>
    Hello World
</p>

Commands

bbm_function

Defines a function that can be called later in the Lava code. The first parameter is the name of the function to define. Further parameters define the names of variables that will be provided to the function body. The data passed to the filter is made available as the Input variable.

Example

"GroupId": 67
{% bbm_function ShowGroup %}
    <li>{{ Input.Name }}</li>
    {% if Input.Groups != empty %}
        <ul>
            {% for g in Input.Groups %}
                {{ g | BBM_Function:'ShowGroup' }}
            {% endif %}
        </ul>
    {% endif %}
{% endbbm_function %}

{% assign group = GroupId | GroupById %}
<ul>
    {{ group | BBM_Function:'ShowGroup' }}
</ul>
<ul>
    <li>General Groups</li>
    <ul>
        <li>Adult Groups</li>
        <ul>
            <li>Decker Group</li>
            <li>Pete's Group</li>
        </ul>
    </ul>
</ul>