【问题标题】:How can I add the filename of each used templates and includes in freemarker templates as HTML comments?如何添加每个使用的模板的文件名并包含在 freemarker 模板中作为 HTML 注释?
【发布时间】:2012-03-03 00:28:16
【问题描述】:

有没有办法配置 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

我只想将此类功能用于调试目的,以便更容易找出哪些 HTML 片段在哪个模板中呈现。

有什么提示吗?

【问题讨论】:

    标签: templates freemarker


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-19
      • 1970-01-01
      • 2013-05-28
      • 1970-01-01
      • 2010-10-17
      • 2014-05-10
      • 2014-05-16
      • 2012-08-15
      相关资源
      最近更新 更多