#Handlebars Function

1 messages · Page 1 of 1 (latest)

glad sundial
#

Hey, I like to add the current date within the template to create a current year copyright text.
Is this possible with handlebars?

worn nicheBOT
#

Hi @glad sundial, 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 @worn niche with any follow-up questions.

#

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'}}

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) .

glad sundial
#

is this possible without an variable?

#

@worn niche is this possible without an variable?

worn nicheBOT
#

Thanks for the follow-up, @glad sundial. I'll get back to you soon.

#

Answer

Sorry, I wasn't able to find any information about your question.

worn nicheBOT
barren tiger
#

Hey @glad sundial when you say without variable, you mean without passing this in the payload? or without the handlebars variable syntax?

glad sundial
#

@barren tiger 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.

barren tiger
#

@glad sundial 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, @glad sundial did you check out https://docs.novu.co/echo/quickstart#introduction-to-echo ?

@quaint river @velvet gorgeam I wrong and we can generate year without payload? cc @long skiff

Novu

Novu Echo, the first Notifications as Code workflow engine.

glad sundial
#

@barren tiger 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

glad sundial
#

maybe such use-cases can be generally be handled with global variable context, which can be accesed syste wide within all templates

barren tiger
#

@glad sundial I think if anything, I would allow to access this as a global variable as you mentioned, @velvet gorge @long skiff @quaint river please take a look at let us know what do you think

velvet gorge
#

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 🙏

quaint river