The website crashes when I do .length while writing a custom email template

Hey, I was using Novu's digest feature to send emails. I can do step.events.length which gives me the total number of events. Then I group the events using groupBy as described in this doc https://docs.novu.co/content-creation-design/handlebars-helpers But when I use groupBy, it gives me an items variable. This seems to be a type Object instead of an array. So I'm unable to find the length of this item variable.
{{#each (groupBy step.events "complianceId")}}
{{items.length}}
{{/each}}
{{#each (groupBy step.events "complianceId")}}
{{items.length}}
{{/each}}
Also, the whole website crashes if I do items.length
No description
3 Replies
Ask Inkeep
Ask Inkeep4w ago
Hi @aashishpeepra, I'm an AI assistant for Novu. While a team member reviews this question, I'll see if I can find relevant sources for your question. ----------------------------- While I generate an answer, here are some sources that might be helpful: * Digest Engine * Handlebars & Helpers * Digest multiple events in a single notification * Digest Action Step -----------------------------
Ask Inkeep
Ask Inkeep4w ago
Answer It appears that using items.length within the groupBy helper is causing issues because items is indeed an object and not an array. According to the documentation, the groupBy helper groups items based on a property, but it does not directly provide a length property for these grouped items (1) . Instead, you should iterate through items and count the elements within each group. Here is a modified version of your template using an inline counter to determine the length of each group:
{{#each (groupBy step.events "complianceId")}}
{{#let this.length as |length|}}
{{length}}
{{/let}}
{{/each}}
{{#each (groupBy step.events "complianceId")}}
{{#let this.length as |length|}}
{{length}}
{{/let}}
{{/each}}
: Handlebars & Helpers This workaround creates an inline variable length to store the length of each group.
aashishpeepra
aashishpeepra4w ago
This is the error message I get when I did the above solution { "error": "Missing helper: "let"" } Okay the solution was to use {{#with items as |itemsArray|}} {{itemsArray.length}} {{pluralize itemsArray.length "message" "messages"}} {{/with}}