Search code examples
handlebars.jsjsreport

JsReport & Handlebars. How to Place today's date?


Working with Handlebars and JSReport to setup a "Mail Merge" of sorts. I want to put the Date the mail merge was performed on each.

JSreport allows Javascript and JSON for data and logic, but I'm having trouble getting it going properly. I did try to set a new Date object for the template to pull, but I don't get the value of the date object on the page.

I tried to add var today = new Date(Date.now()); and then {{today}} to the template, but I literally get {today} on the output.


Solution

  • Declare helper function at the bottom part of the jsreport studio as

    function now() {
        return new Date()
    }
    

    And then at the upper part use it as

    {{now}}
    

    Adapt the helper to your formatting needs... Demo here