Html x-tmpl 是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10025856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:34:59  来源:igfitidea点击:

What is x-tmpl?

html

提问by Dyin

Was looking for the answer on the net, but couldn't find anything. This little snack of code really frustrates me, as I can't understand it. (It's part of the plugin called: jQuery File Upload)

一直在网上寻找答案,但找不到任何东西。这个小小的代码点心真的让我很沮丧,因为我无法理解它。(它是插件的一部分:jQuery File Upload)

<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
  <tr class="template-download fade">
    {% if (file.error) { %}
        <td></td>
        <td class="name"><span>{%=file.name%}</span></td>
        <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
        <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
    {% } else { %}
        <td class="preview">{% if (file.thumbnail_url) { %}
            <a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
        {% } %}</td>
        <td class="name">
            <a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
        </td>
        <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
        <td colspan="2"></td>
    {% } %}
    <td class="delete">
        <button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
            <i class="icon-trash icon-white"></i>
            <span>{%=locale.fileupload.destroy%}</span>
        </button>
        <input type="checkbox" name="delete" value="1">
    </td>
  </tr>
{% } %}
</script>
  • So, what type is text/x-tmpl?
  • What are these {%and %}tags?
  • What parser executes this code?
  • ...
  • 那么,什么类型text/x-tmpl
  • 这些{%%}标签是什么?
  • 什么解析器执行这段代码?
  • ...

...but would like to know everything about this.

...但想知道这一切。

采纳答案by NibblyPig

x-tmpl has no real meaning, it simply stops the browser from interpreting the script as javascript.

x-tmpl 没有实际意义,它只是阻止浏览器将脚本解释为 javascript。

It's mostly used with jquery templates or knockoutjs template binding.

它主要与 jquery 模板或Knockoutjs 模板绑定一起使用

At some point, a javascript data object will be used in conjunction with the template to render some html. The values in the data object will replace those marked with {%} and similar in the template, with some {%} sections reflecting code flow such as loops etc.

在某些时候,一个 javascript 数据对象将与模板结合使用来呈现一些 html。数据对象中的值将替换模板中标有 {%} 和类似标记的值,一些 {%} 部分反映了代码流,例如循环等。

I'm not sure which templating library uses {%} however, it's not jquery templates, jsrender or knockout. You'd have to check what libraries are being referenced in the sample code.

我不确定哪个模板库使用 {%} 但是,它不是 jquery 模板、jsrender 或淘汰赛。您必须检查示例代码中引用了哪些库。

回答by Quentin

So, what type is text/x-tmpl?

那么,text/x-tmpl 是什么类型?

A non-standard one. Looks like a template though.

一个非标准的。虽然看起来像一个模板。

What are these {% and %} tags?

这些 {% 和 %} 标签是什么?

Part of the template language.

模板语言的一部分。

What parser executes this code?

什么解析器执行这段代码?

Probably one written in JavaScript and imported in another <script>element on the same page.

可能是用 JavaScript 编写并导入<script>到同一页面上的另一个元素中的。

回答by Shai Coleman

jQuery-File-Uploadhas a dependency on JavaScript-Templateswhich uses the nonstandard text/x-tmplmime type

jQuery-File-Upload依赖于JavaScript-Templates使用非标准text/x-tmplmime 类型

回答by czager

The code above references the project Django Jquery File Upload found here https://github.com/sigurdga/django-jquery-file-upload

上面的代码引用了此处找到的项目 Django Jquery File Upload https://github.com/sigurdga/django-jquery-file-upload

The {% %} are Django template tags. For more information visit https://docs.djangoproject.com/en/dev/ref/templates/

{% %} 是 Django 模板标签。有关更多信息,请访问https://docs.djangoproject.com/en/dev/ref/templates/

These tags will be parsed by the django templating system

这些标签将由 django 模板系统解析