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>

BBM_Sum

Does a mathmatical summation of all numeric values in a collection and outputs the result.

Example

"Items": [
    { "Name": "Shirt", "Price": 15.25 },
    { "Name": "Sweater", "Price": 25.00 },
    { "Name": "Jacket", "Price": 45.50 }
]
Total: ${{ Items | Select:'Price' | BBM_Sum }}
Total: $85.70

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_Call

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.

Any lava variables you set inside a function will only exist in that function, they do not leak back to the scope of the calling Lava code.

Example

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

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

BBM_ComputeHash

Computes the hash of the given string. Hashes are useful in verifying data hasn't been altered or for identifying data in a unique way without the possibility of determining the original data. Supported hashing methods are: SHA1, SHA256, SHA384, SHA512 and MD5. If the hashing method is not specified then it is assumed to be SHA1.

Example

"Name": "Ted Decker"
{{ Name | BBM_ComputeHash:'sha1' }}
8872869c30034bec13e65f789783fcb043646839

BBM_FromBase64

Decodes the base 64 encoded string and returns the resulting data. If the true parameter is passed then the data is returned as a human readable string. If not specified or false is specified then a byte array of the raw data is returned. Base 64 encoded is sometimes returned from API calls and usually must be decoded before it can be used.

Example

"Object": {
    "Id": 23,
    "Data": "VGVkIERlY2tlcg=="
}
{{ Object.Data | BBM_FromBase64:true }}
Ted Decker

BBM_PageRoute

Converts a page identifier into a URL string. The identifier can either be the page Id number, the Guid value or a full page route (as in the example) which contains <PageGuid>,<RouteGuid>. You can optionally pass in a string of parameters to use when generating the URL. The parameters should be separated by ^. Each parameter should consist of a key and value separated by an =. You may also pass in a dictionary object that contains the parameters.

Example

{{ 'Global' | Attribute:'WorkflowEntryPage','RawValue' | BBM_PageRoute:'WorkflowTypeId=10^WorkflowId=324' }}
/WorkflowEntry/10/324

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>

BBM_ToBase64

Converts the provided string into a base 64 encoded string. Input can also be a byte array instead of a string. Often times, data cannot be transmitted or stored in it's existing form because of limitations of the transmit medium. For example, when you attach a JPG image to an e-mail the image cannot be stored as JPG data. This is because the transmission of e-mail messages is limited to printable characters. In these cases, the data is encoded in what is known as base 64 and stored for transmission.

Example

"Object": {
    "Id": 23,
    "Name": "Ted Decker"
}
{{ Object.Name | BBM_ToBase64 }}
VGVkIERlY2tlcg==

Text Filters

BBM_RegExMatches

Performs a regular expression search of the given input string. The first parameter is the regular expression to use when searching the input string. The optional second parameter specifies any flags to use during the regular expression search. Returns a collection of matches. If two matches for the expression are found then a collection of 2 matches will be returned.

Available flags:

  • i = Do comparison in a case-insensitive manner.
  • m = Multiline mode. ^ and $ will match the beginning and end of lines instead of the beginning and end of the entire input.

Each match object contains the following keys:

  • Index = The starting position of this match in the input string.
  • Length = The length of this match.
  • Value = The full string value that matched from the input string.
  • Groups = Collection of capture groups. A capture group is text surrounded by (...). These capture groups can be used as back references during a replace operation, or simply to extract a specific part of the string after a successful match. The first group will always be the entire matched string. So the first capture group that you specificy will be at index 1. Each group contains the following keys:
    • Index = The starting position of this match in the input string.
    • Length = The length of this match.
    • Value = The full string value that matched from the input string.

See https://regex101.com/ for help with constructing your regular expressions.

Example

"TestPhrase": "The quick brown fox jumps over the lazy dog."
Letter 'o' count: {{ TestPhrase | BBM_RegExMatches:'o' | Size }}
{% assign phoneMatches = '123-456-7890' | BBM_RegExMatches'(\d{3})-(\d{3})-(\d}{4})' %}
{% if phoneMatches != empty %}
Area Code is {{ phoneMatches[0].Groups[1].Value }}
{% endif %}
Letter 'o' count: 4
Area Code is 123

BBM_RegExReplace

Replaces a portion of the string passed as the input to the filter with regular expression matching. The first parameter is the regular expression to match against. The second parameter is the replacement string value. An optional third parameter contains any regular expression flags to use. Back-references can be used, as in the second example, but are slightly different than normal regular expression syntax. Normally you would use \1 to indicate the first capture group. .NET uses $1 to indicate the same.

Available flags:

  • i = Do comparison in a case-insensitive manner.
  • m = Multiline mode. ^ and $ will match the beginning and end of lines instead of the beginning and end of the entire input.

See https://regex101.com/ for help with constructing your regular expressions.

Example

"Message": "Hello Ted, how are you?"
{{ 'The Rock is awesome.' | BBM_RegExReplace:'the rock','Rock','i' }}
{{ Message | BBM_RegExReplace:'[Hh]ello (\w+)','Greetings $1' }}
Rock is awesome.
Greetings Ted, how are you?

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>