How to get Web App Item Count?

Hey guys, I have a Custom Module with a field called Location. The options for this field are Melbourne/Sydney.

I have 5 custom module items, 3 assigned to Melbourne, and 2 assigned to Sydney.

How do I get the count of how many have been assigned to Melbourne and output it on the page?

e.g. BC had this -> https://docs.worldsecuresystems.com/reference/modules/webapps/module_webappscount.html - however it only worked with Classifications.

How do I loop all of the custom module items and output just the number ‘3’ onto the page?

Here is my current module:

{% component source: “Grants”, layout: “List”, filterBy: “Location”, filterValue: “Melbourne”, collectionVariable: “citizens”, type: “module” %}

Cheers!

Hi @Khy. Since your component module is set to only list “Melbourne” items then the total items in this collection will be ‘3’. So to get this you should be able to do:
{{citizens.items | size}}

1 Like

If you were outputting all items and needed totals of each “Melbourne” and “Sydney”, you’d need to do a forloop to count those:

{% assign melCounter = 0 %}
{% assign sydCounter = 0 %}

{% for i in citizens.items %}

    {% if i.location == 'Melbourne' %}
        {% assign melCounter = melCounter | plus: 1 %}
    {% endif %}

    {% if i.location == 'Sydney' %}
        {% assign sydCounter = sydCounter | plus: 1 %}
    {% endif %}

{% endfor %}

{{melCounter}} <!-- should equal 3 -->
{{sydCounter}} <!-- should equal 2 -->
2 Likes

Hey Adam, forgot to reply to you earlier but thank you so much, this helped me dearly a few weeks ago!

1 Like