Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Help article on handlebars integration?

rajeev_yadav
Level 4
Level 4

Do we have any help article for handlebars integration in aem?

1 Accepted Solution
Arun_Patidar
Correct answer by
Community Advisor
Community Advisor

There are lots of libraries available like:

https://json2html.com/

Displaying data from a flat JSON file on a Handlebars.js template file rendered with AJAX. · GitHub

AngularJS

VueJs (e.g.javascript - Fliter Json to HTML using Vue JS - Stack Overflow )

Unlike using libraries you can use do with jquery or javascript if structure is not complex and repetative.

View solution in original post

6 Replies
rajeev_yadav
Level 4
Level 4

Hi Arun,

I want to render json response received from ajax using any templating language. I think we can't call sightly template from ajax success method and handlebar could come to rescue here. I want to pass json response to handlebar template and then render converted html on page.

Thanks,

Rajeev

rajeev_yadav
Level 4
Level 4

Below is the scenario..

$.ajax({

        type: 'GET',

        url: 'test.json',

        data: { get_param: 'value' },

        dataType: 'json',

success: function (data) {

   //1.  use any template to convert json response to html block

   //2. Set the response on page(this can be done using jquery once html block is available from template.

});

}

});

Arun_Patidar
Correct answer by
Community Advisor
Community Advisor

There are lots of libraries available like:

https://json2html.com/

Displaying data from a flat JSON file on a Handlebars.js template file rendered with AJAX. · GitHub

AngularJS

VueJs (e.g.javascript - Fliter Json to HTML using Vue JS - Stack Overflow )

Unlike using libraries you can use do with jquery or javascript if structure is not complex and repetative.

View solution in original post

rajeev_yadav
Level 4
Level 4

Thanks Arun.

I will prefer library so that JS & html are separated. Response data is complex and therefore having html template would be a better choice.

json2html seems to be too raw and basic api compared handlebar.

Thanks for the pointers. I will try to integrate handlebar using custom clientlib and see if I encounter any issues during this process.

Thanks,

Rajeev

rajeev_yadav
Level 4
Level 4

Arun,

Just last question - Can we levarage HTL template to render the json response from ajax?