Access to the mustache template that was loaded in the html head tag?

Is there a way to access the contents of the mustache template file, which is loaded via HTML <head> through javascript?

 <link rel="template" href="templates/address.mustache" type="text/html" /> 

or

 <script src="templates/address_field.mustache" type="text/html" charset="utf-8" id="address_template"></script> 

I had successful loading them through ajax and through the <script> in the body, but I'm not sure how to get the file source when downloading as a separate file through the head.

+7
source share
2 answers

Well, you need to use a selector that will get the contents of this html.

With jQuery, it is as simple as:

 var tmpl=$.trim($('#address_template').val()); //trim the white spaces in the template Mustache.to_html(tmpl,json); 
0
source

you need to get a method to catch the value of the template template: below the codes only work on the html page:

 var tmpl=$.trim($('#address_template').val()); //trim the white spaces in the template 

Mustache.to_html (TMPL, JSON);

you need under the codes: " $. get ('template.html' ," your answer trick), you must first upload your template:

 <!DOCTYPE html> 

Names

 <script> $(function() { $.getJSON('/data/speakers.json', function(data) { //var template = $('#speakers-template').html(); // console.log(template); // var info = Mustache.render(template, data); // $('#talktitles').html(info); 

$. get ('template.html', function (template, textStatus, jqXhr) {var info = Mustache.render ($ (template) .filter ('# speakers-template'). html (), data);. $ (' # ') Talktitles HTML (information);});

  }); }); </script> 

0
source

All Articles