Writing dynamic workflow template based on digest count
In the Novu docs (https://docs.novu.co/platform/digest#writing-digest-templates), the digest engine page describes how it is a common use case to show the number of notifcations in the digest, the example given is "John and 5 others liked your photo."
However it's not clear how this can be achieved in Novu and avoid the edge case where if the digest has one notification in it. In the example above, suppose there was one like on a photo, how can we author a template that says "John liked your photo".
Similarly how would you avoid the pluralisation problem: "1 person liked your photo" instead of "3 people liked your photo". It seems like handlebars doesn't have support for this kind of logic.
How would you implement the example in your documentation above?
9 Replies
Hi @dmgarland
Checkout this page
https://docs.novu.co/platform/handlebars#functions-and-their-description
You can use like this
Thank you!
Glad it helped you π
I reckon having a link on the digest engine page to this example and/or the handlebars page would be a good improvement... I've been looking at these docs for WEEKS and didn't notice this
Sorry for your inconvenience @dmgarland
I will link above page on workflows page π
Is there a way to subtract one from the step count? For example, if I do "John and {{step.total_count}} people liked your photo", the step.total_count would be off by one because one of them, "John", is already mentioned.
maybe something like this could work for you?
That's clever! I'll try that right away. Thank you!
DVRL-65 - update handlebar docs - "John and {{step.total_count}} people liked your photo" usecase
{{#each step.events}} {{#if @first}} {{this.name}} {{else}} {{#if @last}} and {{@index}} {{/if}} {{/if}} {{/each}} followed you!
Status
Triage
DevRel