如何使用标签 {%include example.html%} Stencil with Swift

How to use tag {%include example.html%} Stencil with Swift

我在我的项目中嵌入了模板 Stencil (Kitura https://github.com/IBM-Swift/Kitura ,template engine Stencil https://github.com/kylef/Stencil#include)。我不明白如何使用标签 {% include "comment.html" %}。 我的示例,但不起作用。

example.stencil.html

<html>
      <head>
            hello example
            {% include "include.stencil.html" %}
      </head>
</html>

include.stencil.html

<b>I'm here</b>

代码swift

import Stencil 

let pathTemp=Path("include.stencil.html")
let context = Context(dictionary: ["loader": TemplateLoader(paths: [pathTemp])])
do {
    let template = try Template(named: fileName)
    let rendered = try template.render(context)
    return rendered 
}catch
{
    return "Error:\(error)"
}

Error :Error:'include.stencil.html' template not found in ../include.stencil.html

如何使用它,请帮助我。 :)

看起来是因为您在路径中包含了您的文件名。路径应该只是文件位置的路径,不包括文件本身的名称。

let pathTemp=Path("/path/to/my/file/")