Connecting custom modules and events

I needed to get a list of event groups but needed to categorise the layout.
This is working here https://tasbus5.treepl.co/vehicle-inspections/booking

As Treepl event groups can’t be categorised I created a custom module to hold the location details and added a custom field to the events to connect to the custom module (called location2).

So now I’d like to be able to add the number of available spaces next to each list item.

I’ve been playing with this page https://tasbus5.treepl.co/test2 but am clearly out of my depth as I’m getting really odd results.

This is my liquid code :

{% component source: “Inspection Stations”, object: “collection”, collectionVariable: “location”, type: “module” %}
{% component source: “Event”, object: “collection”, collectionVariable: “eventlist”, type: “module” %}

    <ul class="list-unstyled">
        {% for i in location.items %}
        <li><a href="/{{i['urlslug']}}">{{i['name']}}</a>
          {% for i in eventlist.items %}
              {% if eventlist.location2 == location.id %}
              <ul class="list-unstyled">
                  <li>
                   {{eventlist.items[i].name}}  {{eventlist.items[i].capacity | minus : eventlist.items[i].allocation}} 
                   </li></ul>
            {% endif %}
            {% endfor %}
            </li>
        {% endfor %}
    </ul>

I think your Liquid tags are not quite right. Try this instead:

<li>
    {{i.name}}  {{i.capacity | minus : i.allocation}} 
</li>

If this still produces odd results, try changing your variable naming from i to something else unique, ie:

{% for e in eventlist.items %}

and then change your tags within that loop accordingly, ie:

{{e.name}} ...etc.
1 Like

Thanks Adam - I’ve got it partially working. I’m trying to add a count to calculate the number of available events at a location but the count is not adding up (just showing zero). I suspect its a problem with my code. I’m trying this but its not working.

{% assign count = count | plus:’[e.capacity | minus : e.allocation]’ %}

Maybe I need to set the capacity - allocation as a variable? I’ve got count set to zero to begin.

Try removing the square brackets and single quotes, so just:

{% assign count = count | plus: e.capacity | minus : e.allocation %}
1 Like

Thanks Adam - Its working !!.

This is the full code in case anyone else is stuck with connecting custom modules to events

<!-- get collection data for events and custom module -->
    {% component source: "Inspection Stations", object: "collection", collectionVariable: "location", type: "module" %} 
    {% component source: "Event", limit: "1000", object: "collection", collectionVariable: "eventlist", type: "module" %}
    
    <!-- dislay list of locations -->
    <ul class="list-unstyled">
        {% for i in location.items %}
        <li>
            <a href="/{{i['urlslug']}}">{{i['name']}}</a>
            
            <!-- count number of spaces available at that location -->
            {% assign count = 0 %}
                {% for e in eventlist.items %}
                    {% if e.location2 == i.id %}
                        {% assign count = count | plus: e.capacity | minus : e.allocation %}
                    {% endif %}
                {% endfor %}
            
            ({{count}}) 
        {% endfor %}
        </li>
    </ul>
1 Like