N
Novuβ€’15mo ago
dmgarland

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
Pawan Jain
Pawan Jainβ€’15mo ago
Hi @dmgarland Checkout this page https://docs.novu.co/platform/handlebars#functions-and-their-description You can use like this
{{step.total_count}} {{pluralize step.total_count β€œperson” β€œpeople”}} liked your photo
{{step.total_count}} {{pluralize step.total_count β€œperson” β€œpeople”}} liked your photo
dmgarland
dmgarlandOPβ€’15mo ago
Thank you!
Pawan Jain
Pawan Jainβ€’15mo ago
Glad it helped you πŸ˜€
dmgarland
dmgarlandOPβ€’15mo ago
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
Pawan Jain
Pawan Jainβ€’15mo ago
Sorry for your inconvenience @dmgarland I will link above page on workflows page πŸ™
Khong
Khongβ€’14mo ago
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.
Gali Baum
Gali Baumβ€’14mo ago
{{#each step.events}}
{{#if @first}}
{{this.name}}
{{else}}
{{#if @last}}
and {{@index}}
{{/if}}
{{/if}}
{{/each}}
followed you!
{{#each step.events}}
{{#if @first}}
{{this.name}}
{{else}}
{{#if @last}}
and {{@index}}
{{/if}}
{{/if}}
{{/each}}
followed you!
maybe something like this could work for you?
Khong
Khongβ€’14mo ago
That's clever! I'll try that right away. Thank you!
Linear
Linearβ€’14mo ago
Issue DVRL-65 created.
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
Want results from more Discord servers?
Add your server