0

我有一个包含大量引用和元 div 的 ejs 文件。我想通过将所有这些参考资料放在一个不同的文件中来恢复我的生活,并能够将其添加为单个参考资料。

我试过的方法:

<?php include('references.html)' >

<?php include('references.ejs') >

<!--#include virtual="references.html" -->

<!--#include virtual="references.ejs" -->

提前致谢!

4

1 回答 1

0

由于您已经声明您的模板应该在服务器端呈现(因此包含在您的服务器端代码中):

您似乎正在使用 Apache 或一些类似的服务器进程来处理您的代码。大多数此类服务器只会将 PHP 包含(您的前两个示例)或 SSI 包含(您的后两个示例)应用于具有特定扩展名的文件。例如,如果您有一个名称以“.ejs”结尾的文件,大多数服务器将尝试直接提供它,而不通过 PHP 解释器运行它(因此,任何<?php...>指令都将按字面意思传递,而不是处理为包含)或对其应用 SSI 指令。服务器的标准规则是,如果文件名以“.php”(可能还包括“.php4”或“.php5”)结尾,则通过 PHP 运行文件;如果文件名以“.shtml”结尾,则通过 SSI 运行文件(或者有时只是“.html”)。

The solution is to (if you can) configure your server to parse ".ejs" files by PHP or SSI. If that's not possible (and it might not be under typical hosting arrangements), your best bet is to preprocess your source files at development/deployment time using some sort of Web-oriented preprocessor or a general macro processor (e.g M4, should be automatically installed on any Unix/Linux/MacOS system, can be easily installed on any Windows system).

于 2012-07-30T09:47:37.320 回答