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.
Also, the whole website crashes if I do items.length3 Replies
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
-----------------------------
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:
: Handlebars & Helpers
This workaround creates an inline variable length
to store the length of each group.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}}