Rendering partials contextually

260 views
Skip to first unread message

Vineet Kumar

unread,
Oct 5, 2016, 8:55:50 AM10/5/16
to handlebars.java
Hi All,

We have integrated Jknack Handlebars with Sling/AEM (CMS) to do server side rendering of these HBS files (which we call them as Component Views). It was all working fine until we hit a partial (">") use case which doesn't work. Since Sling/AEM is a component based system, I don't have static prefix but a dynamic one since the folder depends on the component which is to be rendered by the current request. Please let me know if anyone was able to get this working?
We tried to inject a custom TemplateLoader but since there is no request/other context available there but only a string path that too of partial (for example ./partial/mypartial.hbs) I am not really able construct path dynamically and resulting in page error. 
We also tried to have a look at partial.java which is the file which calls TemplateLoader but have not been able to figure out how to swap/extend with a custom one.
As a work around, we will have to create a template loader per template to be able to resolve path dynamically but solution is not scalable since it depends on the number of HBS files you got in your system.
Would really appreciate if someone out there knows how to make it work. I don't really want my FE to constrain to either write absolute path or any other helper? IMHO, had TemplateLoader had context, it would have been simple and that makes sense too since from one environment to another, you will need application context to be able to render partials dynamically/contextually. So please let me know what you guys think.

edgar

unread,
Oct 5, 2016, 2:10:07 PM10/5/16
to handlebars.java
Hi Vineet,

 It covers dynamic partials (runtime resolution of partials).
 In your case you should create a helper which has access to the current request (this depends on your Web/MVC framework). From helper, you can apply all logic you want and create/return a dynamic path.
 
 Let me know how it goes.

ps; no need to ask for help in two places (github and google group). If you need/ask for help the right/preferred site is here at google group, still some others ask in github directly and that's fine too. I can't control that, but you should not post in both site.

Thanks.

Vineet Kumar

unread,
Oct 6, 2016, 2:31:11 AM10/6/16
to handlebars.java
Hi Edgar,

Thanks so much for a quick response. Will try and let you know. Apology of posting the same on both sites and will take care of that in future.

Thanks again!
Reply all
Reply to author
Forward
0 new messages