pre-compile JavaScript templates to functions on project build

此生再无相见时 提交于 2019-12-06 07:41:23

I solved this problem using Node.js and coffeescript by making directory of partial templated into executable, pre-compiled functions. Hope this helps.

https://github.com/wookiehangover/jquery-tmpl-jst

I let you decide if you like it or not :)

in you common js library define this function:

function loadTemplate(templateName) {
   $.ajax({
      url: templateName + '.jst',
      success: function(data) {
         $.template(templateName, data);
      }});
}

Then in you master hml file <head></head> section you can add:

<script type="text/javascript">loadTemplate('model-view');</script>
<script type="text/javascript">loadTemplate('another-model-view');</script>

so you can use anywhere in your code

$.tmpl('model-view', your-data)
$.tmpl('another-model-view', your-data)

Hope it helps

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