简体   繁体   English

如何在文件中编写文本/模板并将其包含到项目中

[英]how write text/template in a file and include it to project

I use script type="text/template" for my project and I use a lot of templates, I want write my template in foreign file and include it to my html 我为项目使用脚本type="text/template" ,并且使用了许多模板,我想将模板写在外部文件中并将其包含到html中

If its possible , what type of file must i use and how must write it ? 如果可能,我必须使用哪种类型的文件以及如何编写它?

In a pure JavaScript/HTML environment, you can't easily. 在纯JavaScript / HTML环境中,您很难做到。

Your choices are: 您的选择是:

Use some kind of JavaScript template library 使用某种JavaScript模板库

I'm only familiar with Durandal that uses the Knockout engine. 我只熟悉使用淘汰赛引擎的Durandal

AngularJS seems to be another popular choice. AngularJS似乎是另一个流行的选择。

Most of these packages include far more than just templates and may be overkill. 这些软件包中的大多数软件包不仅包含模板,还包含过多的内容。

Use a server-side template package 使用服务器端模板包

PHP is a popular server-side tool. PHP是一种流行的服务器端工具。

Some HTTP Servers support Server Side Includes , but these are so limited I couldn't actually recommend them. 一些HTTP Server支持Server Side Includes ,但是它们是如此有限,我实际上不推荐它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM