Styled Attributes

Version 1.0.0

Last Updated Dec 11, 2017

Table Of Contents


After installing the plug-in be sure to clear the Rock Cache to ensure that it re-loads all the field types registered in the database.

No extra installation steps are required, other than setting up some attributes to use the new Styled ... field types that are available in the system.


Configuring is simple and straight forward. Create a new attribute and select one of the new field types that have been registered. As an example, let's create a boolean global attribute that displays a FontAwesome icon when set to Yes.

Sample Boolean Attribute

As you can see, this is just a normal Boolean except for the Style Template. In this particular template we are checking the raw attribute value to see if it equates to true. If so then we display a bell icon. Otherwise we display a bell with a slash through it. Below you can see what it looks like with a True value set.

Sample Boolean Attribute Displayed

Sample Templates

Using Entity

Some of the attributes are termed Entity Attributes because their value equates to a specific entity in the database. For example, the Campus attribute (and by extension the Styled Campus attribute) are entity attributes because they represent a specific database entity - the Campus. These type of attributes provide an extra Lava variable called Entity that you can use to get to the actual data of the underlying database object. As an example, if we wanted to display the Campus Id along with the name of the campus, we could do something like the following.

{% if Entity != null %}
    {{ Value }} <span class="badge badge-info">#{{ Entity.Id }}</span>
{% endif %}
Sample Campus Attribute Displayed

Currently, the styled attributes that support Entity are:

  • Styled Campus
  • Styled File

Using Items

Attributes that support multiple selections provide an additional Lava variable called Items that allows you to access all of the selected items. This variable contains a dictionary of key-value pairs that indicate the RawValue and the selected Item of each of the user's selections. The Item portion can either be displayed text for that particular item or the Entity database value, depending on the data available.

Entity Type Attributes

An entity type attribute will provide the entity object in the Value property. This would be the Campuses attribute. In the following example we are checking the Id of each selected campus and if it matches a specific value then we change the label to a danger label.

{% if Value != empty %}
    {% for item in Items %}
        {% assign itemParts = item | PropertyToKeyValue %}
        {% assign label = 'success' %}
        {% if itemParts.Value.Id == 7 %}
            {% assign label = 'danger' %}
        {% endif %}
        <span class="label label-{{ label }}">{{ itemParts.Value.Name }}</span>
    {% endfor %}
{% endif %}
Sample Campuses Attribute Displayed

Text Type Attributes

The other type of multiple choice attributes are simple text value attributes, such as the Multi-Select attribute. Because you enter the keys and values to be used, it has no concept of what that data represents. For these attributes the Value property contains the text that you specified to be related to that particular key. In this example we are checking the length of the displayed text of each item and if it is greater than 10 then we display it using a warning label, otherwise a normal label is displayed.

{% if Value != empty %}
    {% for item in Items %}
        {% assign itemParts = item | PropertyToKeyValue %}
        {% assign len = itemParts.Value | Size %}
        <span class="label label-{% if len > 10 %}warning{% else %}default{% endif %}">{{ itemParts.Value }}</span>
    {% endfor %}
{% endif %}
Sample Multi-Select Attribute Displayed

Adding Extra Text

To this point, we have simply displayed the values given to us using some conditional logic. But there is no reason we can't include extra text to better inform the user what has been selected. A very simplified example, but it also shows that you can access the CurrentPerson variable to do checks against the person the attribute is being displayed for.

Note: The CurrentPerson may not always be available. For example, if the Attribute is in a workflow that is running in the background then there would be no CurrentPerson. This would be the same as if the person viewing the attribute was not logged in.

{% if Value != empty and CurrentPerson.Id == 1 %}
    The actual value is <code>{{ Value }}</code>.
{% else %}
    This value is hidden.
{% endif %}
Sample Single-Select Attribute Displayed

Bullet Lists

By default, a multi-select field displays selected values in a comma separated list. With use of the Styled attribute, we can change that behavior to display a bulleted list of results. However, since we don't want to display a bulleted list in a grid row we are going to make that conditional upon it not being displayed in Condensed format. Note that the unusual indentation is by design. In this case (due to the reasons stated below) we need to ensure we don't have extra white-space before the <ul> element.

{% if Items != empty %}{% if Condensed == true %}        {{ Value }}
{% else %}<ul>
{% for item in Items %}{% assign itemParts = item | PropertyToKeyValue %}        <li>{{ itemParts.Value }}</li>
{% endfor %}</ul>
{% endif %}{% endif %}
Sample Multi-Select Bullets Diplayed

Because the above was displaying in a workflow as a read-only attribute value, we need to add a little extra code to the User Entry Form to get it to display nicely, this is due to the way HTML and the form work. The content we render is placed inside a <p> tag, which does not allow <ul> elements inside, so we end up with an empty paragraph that wastes space. To resolve this, we can place the following snippet in the Pre-HTML option for that attribute on the User Entry Form.

    .control-wrapper > p.form-control-static:empty + ul { margin-top: -34px; }