Question

Photo of Brian Kalwat

0

Accessing Defined Value Attributes in a Content Channel View Block

Hey everyone!


We're implementing a content channel that is a mini blog of sorts for updating our staff on what the upcoming Sunday's service is going to look like.

One of the item attributes in the content channel is a defined value field where the admin can choose one or multiple things that regularly occur or are the "focus" of that Sunday (Baptism, Groups, Ownership, etc). The structure looks as follows:


IMG_0391.JPG


The following lava loops splits and loops through the values, but I haven't been able to find a way to access the attributes of each defined value.


{% for item in Items %}

     {% assign focuses = item | Attribute:'ServiceFocus','Object' %}

     {% assign focusesSplit = focuses | Split: ', ' %}

     <h3>{{ item.StartDateTime | SundayDate | Date:'MM/d/yy' }} - {{ item.Title }}</h3>

     <ul>

          {% for focus in focusesSplit %}

               <li>{{ focus }}</li>

          {% endfor %}

     </ul>

{% endfor %}


Has anyone successfully accessed defined value attributes from a content channel item loop? Any suggestions would be greatly appreciated!

  • Ken Roach

    Brian - would you be kind enough to post an image of what this screen looks like? Thanks.

  • Photo of Jon Edmiston

    2

    Couple of things:

    • Since your working with multiple defined values coming back it's going to be a bit more tricky. Instead of getting the 'Object' back we'll want to get the 'RawValue' instead. This will give us a comma separated list of defined value guids. 
    • We'll then split on the comma like you have except you'll want to split on ',' instead of ', ' (note the extra space)
    • Below is the final solution:
    {% for item in Items %}
    
        {% assign focuses = item | Attribute:'ServiceFocus','RawValue' %}
    
        {% assign focusesSplit = focuses | Split: ',' %}
        
        <h3>{{ item.StartDateTime | SundayDate | Date:'MM/d/yy' }} - {{ item.Title }}</h3>
        
        <ul>
            {% for focus in focusesSplit %}
                {% definedvalue where:'@Guid == "{{ focus }}"' %}
                    <li style="color: #{{ definedvalue | Attribute:'Color' }};"><i class="fa fa-{{ definedvalue | Attribute:'Icon' }}"></i>{{ definedvalue.Value }}</li>
                {% enddefinedvalue %}
                
            {% endfor %}
        </ul>
    
    {% endfor %}

    But... the solution above requires Rock v6 AND it lead to the discovery of a bug in the new Lava commands when filtering on a Guid. I've put in a fix for v6.1 for that. Since I know you are running v6 I'll send you a undocumented workaround for getting this working now.

    One other thing to note that since our query to get the defined value will only ever return a singe record we don't technically need an inner for iterate on (so I left it out).

  • Photo of Brian Kalwat

    0

    Thanks so much Jon!