add mustache temple to require in require.js AMD

允我心安 提交于 2020-01-11 07:38:30

问题


In js you can load a html template in the require part while defining a module. For example:

template file : test.html

<script id="test" type="text/template">
 <div class="q-header-holder">
  <h1> {{ quizName }}</h1>
  <a href="{{ instructionLinks }}" class="q-instruction-btn">Instructions</a>
 </div>
</script>

in module

define(
 ["template/test"],
 function() {
  //.. rest of code ..
 }
);

But this throws error while fetching the file the filename appended with .js extension. Is there any way to include the template in the define block?


回答1:


Yep, use the text plugin - http://requirejs.org/docs/download.html#text

Some extra documentation can be found here - https://github.com/requirejs/text



来源:https://stackoverflow.com/questions/12842798/add-mustache-temple-to-require-in-require-js-amd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!