N
Novu10mo ago
Mei

Discussion: Handlebars helper for digest/non digest

We allow our subscribers to decide whether or not they want digests enabled by putting a filter based on subscriber data on our digest steps. The problem is that taking into account all the states in which a digest with a filter could leave the Handlebars template variables (no step.events, step.events but step.events.length = 1, and step.events.length > 1) results in a very janky template like the below
{{#unless step.digest}}
nondigest stuff with {{payload_property}}
{{else}}
{{#equals step.total_count 1}}
nondigest stuff with {{payload_property}} <- duplicated!!
{{#else}}
digest stuff with {{#each step.events}}{{payload_property}}{{/each}}
{{/equals}}
{{/unless}}
{{#unless step.digest}}
nondigest stuff with {{payload_property}}
{{else}}
{{#equals step.total_count 1}}
nondigest stuff with {{payload_property}} <- duplicated!!
{{#else}}
digest stuff with {{#each step.events}}{{payload_property}}{{/each}}
{{/equals}}
{{/unless}}
I think Novu should provide a Handlebars helper to abstract away the two required unless+equals branches so that the user does not need to duplicate the part of the template intended for non-digest/digests with a single event. I’m willing to write a PR to implement such a helper but thought I should discuss it here before opening an issue
6 Replies
Mei
MeiOP10mo ago
(For complete transparency, a bug in Novu currently prevents a filter on subscriber on a digest step from ever actually passing but the above problem will still be felt for any type of filter on a digest. We’re running a patched version of Novu and I have a GitHub issue waiting to be assigned to me to have that fix pulled upstream. The patches we have should not impact this templating issue)
Zac Clifton
Zac Clifton10mo ago
@Mei can you link the PR?
Mei
MeiOP10mo ago
No PR yet since I've not been assigned the issue and the contribution guidelines are pretty explicit about that I can link the issue though https://github.com/novuhq/novu/issues/5163, and the PR would be just this one change https://github.com/novuhq/novu/commit/9a3de53776fb707dff1febeea97de442aee376e4 @Zac Clifton
Zac Clifton
Zac Clifton10mo ago
I can assign it, if you want to create the pr, I can approve
Pawan Jain
Pawan Jain10mo ago
Thanks @Mei for the PR I requested review from Gali
Want results from more Discord servers?
Add your server