Handlebars, loading external template files

前端 未结 3 1922
一个人的身影
一个人的身影 2021-01-30 11:06

My goal is to put all my Handlebars templates in a single folder, as so:

templates/products.hbs
templates/comments.hbs

I found this snippet in

3条回答
  •  無奈伤痛
    2021-01-30 11:32

    You can read template from External file no need to put html with script tag

    $.get('templates/products.hbs', function (data) {
        var template=Handlebars.compile(data);
        $(target).html(template(jsonData));
    }, 'html')
    

提交回复
热议问题