Question

Photo of Ben Goshow

0

Display Audience(s) in EventItems

I am trying to write some Lava that displays, among other things, the Audience(s) assigned to an event, but I can't get it working. Can anyone tell me if there's a way, as I'm looping through EventItems, to output the EventItemAudiences?

  • Photo of Nick Airdo

    0

    Greetings Ben,

    I'm assuming you're working on the page with a EventItemOccurrencesLava (aka Calendar Item Lava) block such as this page on the demo site.   If you enable the debug option you'll see the object properties that are available.

    Unfortunately, the Event's EventItemAudiences collection is not listed there because the model does not mark it as a [DataMember] or as being available for Lava (via [LavaInclude]).  (This usually happens when we're trying to avoid creating a circular reference with the data that is automatically fetched into the Lava merge fields.) So if you tried to do this it would not work:

    {% for item in Event.EventitemAudiences %}     
       IsRequired: {{ item.IsRequired }}
    {% endfor %}
    

    However this would work to get the EventItemOccurrences from an event:

    {% for item in Event.EventItemOccurrences %}
        Location: {{ item.Location }}
    {% endfor %}

    Of course this and several other reasons are why we created Lava 2.0 (available in Rock v6). With Lava 2 you could do something like this (assuming your page had an Event object in the Lava merge field or if you fetched an event via Lava 2.0 entity commands:

    {% assign id = Event.Id %}
    
    {% eventitemaudience where:'EventItemId == {{id}}' %}
        {% for item in eventitemaudienceItems %}
            Name: {{ item.DefinedValue.Value }},
        {% endfor %}
    {% endeventitemaudience %}
    
    I hope this helps.
  • Photo of Ben Goshow

    0

    I'm working in a list of events/occurrences, so after I changed the 'id' assignment it worked:

    {% assign id = Event.EventItemOccurrence.EventItemId %}

    Thanks for your help!