Push notification templating
Hi, I was wondering if push notification title and body also support some form of templating such as handlebars or JS? I would like to pass an array of names for example and render it as {{ names.length === 1 ? names[0] : names[1] + ' and ' + names[1]}}. Would be nice to have this logic in Novu.
18 Replies
Is it not working now?
Hi @kristofdt
I don't know if it helps but you can add place holders in the template's title and content
Bla bla bla {{ client }} for {{ date }}. Bla bla bla..
Those parameters need to be set in notification's payload:
{ "name": "fcm-demo", "to": { "subscriberId": "sera-12345" }, "payload": { "client": "Serafeim", "date": "Thu, 4 May 2023 08:00" }, "overrides": { "fcm": { "data": { "action": "my_action", "url":"a url" } } } }
I know of the place holders, but I was wondering about logic in the place holders?
Logic should also work
Oh ok, we've implemented logic in the placeholders in the past and seemed fine.
I get this error

I also tried
but it gives the same error
It can be the case that logic don't work.
Can you please create feature request for this?
!feature
GitHub
[NV-1749] 🚀 Feature: Support more logic in the templating. · Issue ...
🔖 Feature description It would be nice to have some more templating options available in titles and body fields. An example would be to pass a list of companyNames and be able to do this: {{company...
Hi @kristofdt
You could try this:
for
Result: comp1, comp2 and comp3
I was wondering if handlebars was supported. If this is the case then my feature request can be closed as well! thank you!
sure 🙂
Might be interesting to add this to the documentation somewhere though?
We have this section in docs https://docs.novu.co/platform/templates#messages
Templates | Novu
A template holds the entire flow of messages sent to the subscriber. This is where all the different channels are tied together under a single entity.
But I agree, we should definitely expand and give more examples
Feel free to ask for/add any missing helpers you find needed
This is where you can find our existing helpers: https://github.com/novuhq/novu/blob/next/apps/api/src/app/content-templates/usecases/compile-template/compile-template.usecase.ts
GitHub
novu/compile-template.usecase.ts at next · novuhq/novu
The open-source notification infrastructure with fully functional embedded notification center - novu/compile-template.usecase.ts at next · novuhq/novu
If you still want to do the length comparison you can use {{#equals array.length 2}} .. {{else}}..{{/equals}}