首页 > 解决方案 > Beego 模板 - 使用带有静态页面的持久模板

问题描述

我正在使用 Beego,并且能够在 index.tpl 页面(具有网站横幅、菜单导航、页脚等)上使用持久模板但是,当我单击索引页面并转到我的一个静态页面,即“联系”页面。永久模板不会出现。如何将持久模板添加到 /static/pages 目录下的所有静态页面。

标签: templatespersistentbeego

解决方案


您应该使用布局概念。

用于主页控制器;

this.Layout = "layout.html"
this.TplNames = "index.html"

用于联系页面控制器;

this.Layout = "layout.html"
this.TplNames = "contact.html"

布局.html

{{template "header.html"}}
{{template "banner.html"}}
{{.LayoutContent}}
{{template "footer.html"}}

LayoutContent 变量引用控制器的 TplNames 文件。

https://beego.me/docs/mvc/view/view.md


推荐阅读