jsreport / jsreport-handlebars

jsreport handlebars templating engine
GNU Lesser General Public License v3.0
2 stars 4 forks source link

Handlebars partial #4

Open vinayk047 opened 6 years ago

vinayk047 commented 6 years ago

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?

vinayk047 commented 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

bjrmatos commented 6 years ago

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"],
    ...
  }
  ...
}
bjrmatos commented 6 years ago

i'm leaving the issue open just to see if we want to discuss built-in handlebars's partial support in the future.

vinayk047 commented 6 years ago

@bjrmatos , Thank you for your quick reply on this. Provided workaround works perfectly.

I just had to do following

  1. Change the configuration of jsreport to allow handlebars module (as mentioned above)
  2. Create partial as asset via jsreport studio
  3. Than for template register the partial in script section
  4. Call partial from template

Thank you @bjrmatos :+1:

acras commented 6 years ago

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

pofider commented 6 years ago

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

acras commented 6 years ago

@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?

pofider commented 6 years ago

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

thehappycoder commented 4 years ago

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?

bjrmatos commented 4 years ago

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