N
Novu8mo ago
SHG-TV

Handlebars Function

Hey, I like to add the current date within the template to create a current year copyright text. Is this possible with handlebars?
12 Replies
Ask Inkeep
Ask Inkeep8mo ago
Hi @SHG-TV, I'm an AI assistant for Novu. While a team member reviews this question, I'll look through relevant sources and see if I can provide suggestions. Please tag @Ask Inkeep with any follow-up questions. ----------------------------- While I generate an answer, here are some sources that might be helpful: * Handlebars & Helpers * Send Your First Notification * Digest Engine * Translations -----------------------------
Ask Inkeep
Ask Inkeep8mo ago
Answer Yes, it's possible to add the current date within the template using Handlebars with Novu. You can use the dateFormat handlebar helper function provided by Novu to format the date. For example, to display the current year, you can use the following syntax:
{{dateFormat now 'YYYY'}}
{{dateFormat now 'YYYY'}}
This will render the current year in your template. Ensure that you pass the current date to the template in the appropriate variable (in this case, now) when triggering the notification. Refer to the Novu documentation for more details on handlebars and helpers (1) .
SHG-TV
SHG-TVOP8mo ago
is this possible without an variable? @Ask Inkeep is this possible without an variable?
Ask Inkeep
Ask Inkeep8mo ago
Thanks for the follow-up, @SHG-TV. I'll get back to you soon. ----------------------------- While I generate an answer, here are some sources that might be helpful: * Translations * Java * Email * Ruby ----------------------------- Answer Sorry, I wasn't able to find any information about your question. Got it. Tagging @Support for additional help.
Tomer Barnea
Tomer Barnea8mo ago
Hey @SHG-TV when you say without variable, you mean without passing this in the payload? or without the handlebars variable syntax?
SHG-TV
SHG-TVOP8mo ago
@Tomer Barnea we want to achieve this without passing payload from the trigger. the use case is to have a self-updated year within a copyright text.
Tomer Barnea
Tomer Barnea8mo ago
@SHG-TV got it, thanks! I did some testing myself, I cant see it available right now, so you'd have to pass your own as it stand right now. A couple of solutions I can think of, 1 is to add a new handlebars helper, another one is Echo, @SHG-TV did you check out https://docs.novu.co/echo/quickstart#introduction-to-echo ? @Pawan Jain @Dima Grossmanam I wrong and we can generate year without payload? cc @radek
Novu
Quick Start - Novu
Novu Echo, the first Notifications as Code workflow engine.
SHG-TV
SHG-TVOP8mo ago
@Tomer Barnea Yeah, I know eacho, but we are currently not using it. Would it be an option to add a handlebars helper globally for all? I think this could be a common use-case maybe such use-cases can be generally be handled with global variable context, which can be accesed syste wide within all templates
Tomer Barnea
Tomer Barnea8mo ago
@SHG-TV I think if anything, I would allow to access this as a global variable as you mentioned, @Dima Grossman @radek @Pawan Jain please take a look at let us know what do you think
Dima Grossman
Dima Grossman8mo ago
I think broadly a global context will be the best way to go, but will require more effort. For now easier will be to add a dedicated handlebars helper. As Tomer mentioned this can be easily achieved with Echo. For the handlebars helper, i don’t have any estimates, but feel free to submit a PR 🙏
Pawan Jain
Pawan Jain8mo ago
@SHG-TV Added a github issue for this https://github.com/novuhq/novu/issues/5376
SHG-TV
SHG-TVOP8mo ago
thanks alot 🙂
Want results from more Discord servers?
Add your server