与Go Fiber模板引擎一起使用时,我无法在小胡子中获取部分内容{{标题}}</</desc> <question vote="2"> <p>我正在尝试为我的网站创建一个布局,其中我对页眉和页脚使用部分内容。</p> <pre><code> <!DOCTYPE html> <html lang="en"> <head> <title>{{title}}</title> <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" data-cfemail="0f677b627721607d684f3e21362136">[email protected]</a>" crossorigin="anonymous"></script> <link href='/static/css/global.css' rel='stylesheet'> <link href='https://fonts.googleapis.com/css?family=Rubik' rel='stylesheet'> </head> <body> {{> views/partials/header }} {{{embed}}} {{> views/partials/footer }} </body> </html> </code></pre> <p>我按照此处所示的示例进行操作:<a href="https://stackoverflow.com">https://docs.go Fiber.io/template/mustache/</a></p> <p>嵌入工作正常,但部分不起作用。</p> <p>我的文件结构是这样的:</p> <pre><code>views ├── layout.mu └── partials ├── header.mu └── footer.mu </code></pre> <p>这是我如何设置应用程序和路线:</p> <pre><code>engine := mustache.New("./views", ".mu") app := fiber.New(fiber.Config{Views: engine}) app.Get("/", func(c *fiber.Ctx) error { return c.Render("index", fiber.Map{ "title": "index", }, "layout") }) </code></pre> <p>最后这是我的标题:</p> <pre><code><nav class="navigation"> <a href="/"><img alt="" class="logo" src="/static/images/logo.png"/></a> <ul class="items"> <li> <a class="links" href="/product">Produkt</a> </li> <li> <a class="links" href="/blog">Blogg</a> </li> <li> <a class="links" href="/about">Om Oss</a> </li> <li> <a class="links contact" href="/contact">Kontakta Oss</a> </li> </ul> </nav> </code></pre> </question> <answer tick="false" vote="0"> <p>我想你现在可能已经解决了。 但对于未来的用户,我将解决方案发布在这里。</p> <p>文件扩展名必须是 <pre><code>.mustache</code></pre>,否则模板引擎将无法从包含的部分文件中渲染文件。</p> </answer> </body></html>

问题描述 投票:0回答:0
go mustache go-fiber
© www.soinside.com 2019 - 2024. All rights reserved.