templates - Beego 模板 - 使用带有静态页面的持久模板
问题描述
我正在使用 Beego,并且能够在 index.tpl 页面(具有网站横幅、菜单导航、页脚等)上使用持久模板但是,当我单击索引页面并转到我的一个静态页面,即“联系”页面。永久模板不会出现。如何将持久模板添加到 /static/pages 目录下的所有静态页面。
解决方案
您应该使用布局概念。
用于主页控制器;
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 文件。
推荐阅读
- php - 无法使用 VPN 和 WSL2 连接 SQL Server 数据库
- sql-server - 如何始终以相同的顺序返回行
- bash - Bash 脚本将日志从一个 pod 分离到另一个
- excel - Adding a note to a cell based on another cell
- node.js - 在 Node.js 模板中加载内联脚本,然后将其发送到客户端
- haskell - 使用 QuickCheck 将 ST 与多态测试“模板”一起使用
- esp32 - 如何将 ESP32 设置为最大 BLE 功率?
- python - 如何解释打印在张量流模型摘要中的输出形状?
- javascript - 在函数调用中解包数组
- python - AttributeError:模块“tensorflow._api.v1.config”没有属性“run_functions_eagerly”