phantom-pdf handlebars in header
-
Hi I am trying to use handlebars in my phantom pdf header, see snipit from header below:
<p style="text-align: right;"><span style="font-family: calibri, sans-serif;">{{RunDate}}</span></p>
This does work as expected the first time I run the report. When running the report a second time, the {{RunDate}} is replace with the static text from the first run, see snipit from modified header below:
<p style="text-align: right;"><span style="font-family: calibri, sans-serif;">2018-07-03</span></p>
All future reports will now have the date of the first report.
We are using jsreports ver 2.0 installed on our own server.
- Is this expected behavior?
- How do I prevent the header from be modified when running a report?
Thanks
-
hi! where
RunDate
comes from? from a data json file? what should be the value ofRunDate
in second run? are you expecting to show minutes and seconds? if you are calculatingRunDate
with the date of today it will always be2018-07-03
in all runs of today. can you clarify more?
-
Thanks for the fast reply. Yes RunDate is a field in a JSON object, it is included in the sample data that I've used to build the report. It is also in a JSON object that I send in via the API. Both options for running the report have the same issue, after saving the report header with a set of handle bars, it works correctly only for the first run. There is another field in the header {{Pharmacy.Contact.Name}} that also works the same way. The name is correct for the initial run only. I use the Run button within jsreports only to design the report. Our API will then make requests whenever a new report is required via axios.
return axios.post(
requestUrl,
{
template: { shortid: 'rJ89zTUbm' },
data: report
},
{
responseType: 'arraybuffer'
}
);
We recently switched from jsreports 1.8 to 2.0. We did not experience the issue with 1.8.
-
hmm ok, i'm getting a little bit confused, let's take the case when you run just from jsreport studio.. if the
RunDate
comes from sample data i guess the value there it is always{ "RunDate": "2018-07-03" }
, so in first run it prints2018-07-03
in header, now in second run, what do you do? do you update the sample data to another different date (let's say2018-07-04
)? so when you run the report (for the second time) it shows the old value2018-07-03
even if you have changed the value in sample data, is that right?
-
Confuses me also :) . I'll describe this using a different field {{Name}}, corresponding JSON object is { "Name": "Sample Store" }
Step 1) Create a template for the report and add a header that includes {{Name}}.
Step 2) Create the sample JSON object with the required field { "Name": "Sample Store" }
Step 3) Verify the report is correct by clicking the "Run" button. The PDF is rendered correctly with the value of {{Name}} correctly rendered on the PDF.
Step 4) Submit the report from another node application within our system, send in a JSON object with a new JSON object { "Name": "Store ABC" }.
Step 5) The new report is rendered with the sample data "Sample Store".
Step 6) Open the template in jsreports studio to view the header, the {{Name}} element has been replaced with "Sample Store".
-
ok, thanks for the steps (they are really helpful), i will try the same in latest v2 and check if i can reproduce it
-
Thanks, one additional piece of information, the handlebars are being replaced by static text in the header definition only, otherwise the handlebars work as expected. Also, I'm using phantom-pdf.
-
i can reproduce the issue that you are describing, we will investigate the problem and fix it, thanks for issue report