2016-09-21 66 views
1

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

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

如何使用它,帮我PLZ。 :)

回答

0

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

let pathTemp=Path("/path/to/my/file/") 
相关问题