0

EDIT : The problem is, when my html page is generated by Node/express/hbs, the handlebars parser try to resolve the blocks inside the script tags, it can't so it is just ignoring it, is there a way to make handlebars ignore the content of the script tags ?

Here is my Handlebars template file

<section id="movies-to-sort"></section>
<script id="movies2sort" type="text/x-handlebars-template">
<ul>
  {{#movies}}
  <li>
   <p>{{name}} <small>({{ext}})</small></p>
  </li>
  {{/movies}}
</ul>
</script>

Then I have this ajax done() function :

.done(function(datas) {

    var source = $('#movies2sort').html();

    var template = Handlebars.compile(source, {noEscape: true});
    
    $("#movies-to-sort").html(template(JSON.stringify(datas)));
    // I have also tried without stringifying the datas
});

Here is the raw datas from the ajax response in firefox

{"movies":[{"name":"8½ - Otto et Mezzo (1963) 720p [MKV Corp].mkv","ext":"mkv"},{"name":"Al Final del Tunel (2016) 720p [MKV Corp].mkv","ext":"mkv"},{"name":"Banshun (Printemps Tardif)(1949) 720p [MKV Corp].mkv","ext":"mkv"},{"name":"Beasts of the Southern Wild (2012) 720p.mkv","ext":"mkv"},{"name":"Cashback (2006) 720p [MKV Corp].mkv","ext":"mkv"},{"name":"Celeste & Jesse Forever (2012) 720p.mkv","ext":"mkv"},{"name":"Citizen Kane (1941) 720p [MKV Corp].mkv","ext":"mkv"},{"name":"Das Boot (1981) [MKV Corp].mkv","ext":"mkv"},{"name":"It's a Wonderful Life (1946) 720p [MKV Corp].mkv","ext":"mkv"},{"name":"Jodaeiye Nader az Simin - Une Separation (2011) 720p.mkv","ext":"mkv"},{"name":"Ne Nous Fâchons Pas (1966) [STEN] 720p by johnchen [MKV Corp].mkv","ext":"mkv"},{"name":"Seven Psychopaths (2012) 720p.mkv","ext":"mkv"},{"name":"Tasogare Seibei (Le Samouraï du Crépuscule)(2002) 720p.mkv","ext":"mkv"},{"name":"The Artist (2011) 1080p [MKV Corp].mkv","ext":"mkv"},{"name":"The Aviator (2004) 720p [MKV Corp].mkv","ext":"mkv"},{"name":"The Big Short - Le Casse du Siècle (2015) 720p [MKV Corp].mkv","ext":"mkv"},{"name":"The Blues Brothers (1980) 720p [MKV Corp].mkv","ext":"mkv"},{"name":"The Bourne Identity (2002) 720p [MKV Corp].mkv","ext":"mkv"}]}

But the only html thing which is inserted in is an empty html list, the {{#movies}}{{/movies}} is always ignored.

<section id="movies-to-sort">
   <ul></ul>
</section>

I feel I am very close, but I can't figure out what is wrong, any help/hint will be appreciated.

escteban
  • 26
  • 2
  • Does this answer your question? [How to iterate over array of objects in Handlebars?](https://stackoverflow.com/questions/22696886/how-to-iterate-over-array-of-objects-in-handlebars) – Siddharth Seth Jul 15 '20 at 07:09
  • No, my question is : how to make the HBS template compiler (used in Node.js/Express context) ignore the content of tags. – escteban Jul 15 '20 at 17:00
  • There is a discussion at https://stackoverflow.com/questions/23605254/handlebars-avoid-compiling-ignore-part-of-a-template Basically the solution here talks of using raw-helper. More details about the same is available at https://handlebarsjs.com/guide/block-helpers.html#raw-blocks – Siddharth Seth Jul 15 '20 at 17:47

0 Answers0