【问题标题】:Martini render shows {{ yield }} on pageMartini 渲染在页面上显示 {{ yield }}
【发布时间】:2015-09-13 11:31:03
【问题描述】:

我尝试在马提尼中呈现我的页面 布局.html

<!DOCTYPE html>
<html lang="en">
    <head>...</head>
    <header>...</header>
    {{ yield }}
    <footer>...</footer>
</html>

index.html

<main>
    <h1>Hello</h1>
</main>

渲染选项:

m.Use(render.Renderer(render.Options{
        Directory:  "templates",                
        Layout:     "layout", 
        Extensions: []string{".tmpl", ".html"},
        Delims:     render.Delims{"{[{", "}]}"}, 
        Charset:    "UTF-8",  
        IndentJSON: true, 
}))

尝试显示页面:

rnd.HTML(200, "edit", nil)

运行应用程序并查看我的页面:

layout.html 中的所有代码都正常处理,但 {{ yield }} 字符串保持不变。

【问题讨论】:

    标签: go render martini


    【解决方案1】:

    您将分隔符设置为“{[{”和“}]}”,但随后使用“{{”和“}}”。

    使用Delims: render.Delims{"{{", "}}"}, 或更改您的模板以使用{[{ yield }]}

    【讨论】: