Registering a partial in handlebars

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Registering a partial in handlebars

Nipuni Salgado
Hi all,

Currently, I'm working with the WSO2 TCC team on the project 'Automate Reference Documentation for Configuration Files'.

The implementation of the project is done by using the JavaScript implementation of handlebars - handlebars.js [1].

In my implementation the json object which need to be passed to the handlebars partials is stored in a json file. What I need to do is read the json object from that file and pass that object as the context to the handlebars partials.

I tried doing it as shown in the following code snippet,
$.getJSON(path, function(json) {
var source = $("#main").html();
var template = Handlebars.compile(source);
var context = json;
Handlebars.registerPartial('generateDoc', $("#generateDoc").html());
Handlebars.registerPartial('generateYamlDoc', $("#generateYamlDoc").html());
var output = template(context);
$("#content").html(output);
});

But when I debug it gives an error, "Error: Attempting to register a partial called "generateDoc" as undefined".

Therefore, I need to know how to register a partial using handlebars.js and how to pass a json object as the context to the registered partial.

Appreciate your help on this matter.


Thank you.

Nipuni Salgado
Trainee Software Engineer
WSO2

Mobile: <a href="tel:+94%2077%20997%203350" value="+94779973350" target="_blank">+94779973350
Web: http://wso2.com



_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Registering a partial in handlebars

Yasima Dewmini
Hi Nipuni,

Can you try as following without using Jquery? It worked for me.

Handlebars.registerPartial("generateDoc", document.getElementById("generateDoc").innerHTML);

Refer [1] for more information.

Regards,
Yasima.

On Wed, Dec 6, 2017 at 9:30 AM, Nipuni Salgado <[hidden email]> wrote:
Hi all,

Currently, I'm working with the WSO2 TCC team on the project 'Automate Reference Documentation for Configuration Files'.

The implementation of the project is done by using the JavaScript implementation of handlebars - handlebars.js [1].

In my implementation the json object which need to be passed to the handlebars partials is stored in a json file. What I need to do is read the json object from that file and pass that object as the context to the handlebars partials.

I tried doing it as shown in the following code snippet,
$.getJSON(path, function(json) {
var source = $("#main").html();
var template = Handlebars.compile(source);
var context = json;
Handlebars.registerPartial('generateDoc', $("#generateDoc").html());
Handlebars.registerPartial('generateYamlDoc', $("#generateYamlDoc").html());
var output = template(context);
$("#content").html(output);
});

But when I debug it gives an error, "Error: Attempting to register a partial called "generateDoc" as undefined".

Therefore, I need to know how to register a partial using handlebars.js and how to pass a json object as the context to the registered partial.

Appreciate your help on this matter.


Thank you.

Nipuni Salgado
Trainee Software Engineer
WSO2

Mobile: <a href="tel:+94%2077%20997%203350" value="+94779973350" target="_blank">+94779973350
Web: http://wso2.com



_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev




--
Software Engineer, WSO2, Inc.
Mobile: +94713117081

_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Registering a partial in handlebars

Nipuni Salgado
Hi Yasima,

I'll try that and see.

Thank you.

On Wed, Dec 6, 2017 at 2:34 PM, Yasima Dewmini <[hidden email]> wrote:
Hi Nipuni,

Can you try as following without using Jquery? It worked for me.

Handlebars.registerPartial("generateDoc", document.getElementById("generateDoc").innerHTML);

Refer [1] for more information.

Regards,
Yasima.

On Wed, Dec 6, 2017 at 9:30 AM, Nipuni Salgado <[hidden email]> wrote:
Hi all,

Currently, I'm working with the WSO2 TCC team on the project 'Automate Reference Documentation for Configuration Files'.

The implementation of the project is done by using the JavaScript implementation of handlebars - handlebars.js [1].

In my implementation the json object which need to be passed to the handlebars partials is stored in a json file. What I need to do is read the json object from that file and pass that object as the context to the handlebars partials.

I tried doing it as shown in the following code snippet,
$.getJSON(path, function(json) {
var source = $("#main").html();
var template = Handlebars.compile(source);
var context = json;
Handlebars.registerPartial('generateDoc', $("#generateDoc").html());
Handlebars.registerPartial('generateYamlDoc', $("#generateYamlDoc").html());
var output = template(context);
$("#content").html(output);
});

But when I debug it gives an error, "Error: Attempting to register a partial called "generateDoc" as undefined".

Therefore, I need to know how to register a partial using handlebars.js and how to pass a json object as the context to the registered partial.

Appreciate your help on this matter.


Thank you.

Nipuni Salgado
Trainee Software Engineer
WSO2

Mobile: <a href="tel:+94%2077%20997%203350" value="+94779973350" target="_blank">+94779973350
Web: http://wso2.com



_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev




--
Software Engineer, WSO2, Inc.
Mobile: <a href="tel:+94%2071%20311%207081" value="+94713117081" target="_blank">+94713117081



--
Nipuni Salgado
Trainee Software Engineer
WSO2

Mobile: +94779973350
Web: http://wso2.com



_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev