Templates 如何添加每个使用过的模板的文件名,并将其作为HTML注释包含在freemarker模板中?

Templates 如何添加每个使用过的模板的文件名,并将其作为HTML注释包含在freemarker模板中?,templates,freemarker,Templates,Freemarker,是否有一种方法可以配置freemarker,以便freemarker模板引擎自动将当前模板的名称插入为HTML注释 我希望看到的HTML输出示例: <!-- template file: main.ftl --> normal template code of the file main.ftl <!-- template file: myinclude.ftl --> This is the code from myinclude.ftl 文件main.ftl的常

是否有一种方法可以配置freemarker,以便freemarker模板引擎自动将当前模板的名称插入为HTML注释

我希望看到的HTML输出示例:

<!-- template file: main.ftl -->
normal template code of the file main.ftl

<!-- template file: myinclude.ftl -->
This is the code from myinclude.ftl

文件main.ftl的常规模板代码
这是myinclude.ftl中的代码
我只想将这些功能用于调试目的,以便更容易找到在哪个模板中呈现的HTML片段


有什么提示吗?

您可以编写一个
TemplateLoader
实现,它只委托给另一个
TemplateLoader
(在不处于调试模式时使用的一个),但捕获它返回的流,并在
指令后插入HTML注释。(但不要在注释中添加换行符,否则会偏移错误消息中的行号;请改用
${'\n'}${'\n'}
。)