【问题标题】:Beego Templates - Use persistent template with static pagesBeego 模板 - 使用带有静态页面的持久模板
【发布时间】:2019-12-09 23:15:07
【问题描述】:

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

【问题讨论】:

    标签: templates persistent beego


    【解决方案1】:

    您应该使用布局概念。

    用于主页控制器;

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

    用于联系页面控制器;

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

    layout.html

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

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

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

    【讨论】:

      猜你喜欢
      • 2015-07-19
      • 2013-02-11
      • 1970-01-01
      • 2015-07-14
      • 1970-01-01
      • 2018-03-09
      • 2018-12-21
      • 2019-09-06
      • 1970-01-01
      相关资源
      最近更新 更多