Open vinayk047 opened 6 years ago
basically i wanted to do recursion on some data set via handlebar; and using handlebars partial is one of the way to do recursion that I'm aware of.
following is one of the recursion example in handlebar https://codepen.io/fbadaro/pen/raGdGv
you can achieve the same result using assets, and treating your partials as jsreport assets, the reason we don't have built-in support for partials is because partials unlike helpers is not a feature that is common between other template engines (maybe it is now, but at the time of its creation it was not).
however if you really want to use handlebars's partial you can do the following: https://playground.jsreport.net/studio/workspace/HynbIHQdb/11
just make sure to allow the handlebars
module in your local jsreport config.
{
...
"tasks": {
...
"allowedModules": ["handlebars"],
...
}
...
}
i'm leaving the issue open just to see if we want to discuss built-in handlebars's partial support in the future.
@bjrmatos , Thank you for your quick reply on this. Provided workaround works perfectly.
I just had to do following
Thank you @bjrmatos :+1:
Hello. We are testing some reporting tools and jsReports is one candidate. I am really liking the philosophy of the tool. We use Ember and Handlebars, so the feature of allowing the native use of hbs partials would be a plus for us.
Thank you
@acras Glad you like what we do. Have you tried registering partials using the way described in the previous comments? Is there something it doesn't cover for you? So far we think this should be enough and we just need to document it.
@pofider it looks enough for me. The only reason I +1 this request is that as an undocumented solution it could "disappear". But with your reply now I know I can rely on that. I'll have to handle 1000+ templates with dozens of partials, do you think it will jeopardize the performance if I enclosure all the Handlebars.registerPartial calls in one function an call that function on every report?
@acras Hmm. You are usually interested in rendering pdf. Html to pdf conversion is so expensive task for resources that some handlebars helpers/templates/partials performance is irrelevant in most cases.
As I understand, https://jsreport.net/learn/child-templates#set-child-template-parameters may be a better solution that would work with other engines as well?
@thehappycoder yes, both assets and child templates are better solutions in the context of jsreport. and assets being the recommendation for most of the cases.
I tried to register handlebar partial; but every time it is giving error that partial could not be found. so, does jsreport supports handlebar partial? if not do we have any workaround for this?