我在我的项目中嵌入了模板 Stencil(Kitura https://github.com/IBM-Swift/Kitura,模板引擎 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>
快速代码
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/")
关于swift - 如何在 Swift 中使用标签 {%include example.html%} Stencil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39606953/