swift - 如何在 Swift 中使用标签 {%include example.html%} Stencil

标签 swift stencils kitura

我在我的项目中嵌入了模板 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/

相关文章:

c - 无法检测为什么以下代码未矢量化

javascript - Swift 中的 === 和 !== 是什么?和 JS 一样吗?

iOS:无法检测到 CALayer 边界外的触摸

ios - Swift:我可以在集合/表格 View 单元格中加载 Url 数据吗?

javascript - 在 bigcommerce 模板框架中的类别页面上显示样本颜色

swift3 - 如何使用 swift 3 进行同步 url 请求

swift - 有什么简单的方法可以远程调试在(开发)服务器上运行的快速(vapor/perfect/kitura)应用程序?

ios - 在字典 Swift iOS 中过滤字典数组中的 json 响应

ios - 在 UITableViewCell 中为 UICollectionView 设置一个导出