question

Sherpa-7962 avatar image
0 Votes"
Sherpa-7962 asked YijingSun-MSFT answered

How to refer either Handlebar or Mustache js files in a jQuery plugin

I am new to the jQuery plugin and Handlebar/Mustache template development. I am in the process of creating a jQuery plugin to show a modal popup. The code below is my plugin at the earliest iteration. It works. I want to move all the HTML code to the plugin section and plan to use Hanlebar.js or Mustache.js templates to construct the popup window HTML. I am not sure how to refer to either the Hanlebar.js or Mustache.js files or their CDN's in the plugin.

 (function ($) {

 $.fn.popup = function () {

     $("#startOverModal").modal("show");

 };

}(jQuery));

dotnet-csharpdotnet-aspnet-webforms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YijingSun-MSFT avatar image
0 Votes"
YijingSun-MSFT answered

Hi @Sherpa-7962 ,
According to your description,I think you want to use template to replace the modal's context. You could refer to below codes:

 <script type="text/x-handlebars" id="place-modal-template">
     <div id="my-modal" (...)
 </script>
 <div id="modal-container"></div>
    
 var place = {...}
 var template = Handlebars.compile($("#place-modal-template").html());
 $("#modal-container").html(template(place));
 $("#my-modal").modal();

Best regards,
Yijing Sun


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.