【问题标题】:grails header title not working with layout - sitemesh and layoutgrails 标题标题不适用于布局 - 站点网格和布局
【发布时间】:2014-02-24 06:11:55
【问题描述】:

我有一个基本页眉布局 (base-header-footer.gsp)

<!DOCTYPE html>
<html>
    <head>
        <title><g:layoutTitle default="${g.message(code: 'title.index.page')}"/></title>
    </head>
    ... some common resources loading....
     <body id="launch">
    <g:layoutBody/>
   ...........................
    <r:layoutResources />
    </body>
</html>

然后还有 2 个标题,一个用于登录用户,另一个用于访客用户,这两种标题布局都扩展了基本布局。

访客用户 (anonymouys-header-footer.gsp) -

<g:applyLayout name="base-header-footer"> 
<!DOCTYPE html>
    <html>
    <head>
        <g:layoutHead/>
    </head>
    <body>
        ... render guest user header
        <g:layoutBody/>         
    </body>
</html>

登录用户 (loggedin-header-footer.gsp) -

<g:applyLayout name="base-header-footer"> 
<!DOCTYPE html>
    <html>
    <head>
        ... some css
        <g:layoutHead/>
    </head>
    <body>
        ... Render header for logged-in user
    </body>
            ... load some JS file...
</html>

现在在特定页面中,我根据用户的登录状态应用访客或登录布局,因此我想显示页面特定标题用户正在打开,但它不起作用。

这就是我使用这些布局的方式

OrderStatus.gsp -

<!DOCTYPE html>
<html>
    <head>
        <title>Order status | Some title</title>
        <meta name="layout" content="logged-in-header-footer" />
        <script type="text/javascript" src="${resource(dir:'js',file:'some.js')}"></script>
       </head>
    <body>

    </body>
</html>

但我仍然看到定义为 base-header-footer.gsp 的标题,不是 OrderStatus.gsp 中的标题

我也尝试在 OrderStatus.gsp 中使用 g:layoutTitle,但没有帮助。

非常感谢任何帮助。

【问题讨论】:

    标签: grails layout gsp


    【解决方案1】:

    使用

    <meta name="layout" content="base-header-footer">
    

    在您的页面中加载布局,然后在此处添加您的标题,

    <title>${whatever.something()}</title>
    

    在你的布局中添加这个:

    <title><g:layoutTitle/></title>
    

    享受吧。

    【讨论】:

      【解决方案2】:

      尝试使用

      <title><g:layoutTitle/></title>
      

      在您的布局中(base-header-footerloggedin-header-footer.gsp)。更多信息在official documentation

      【讨论】:

      • 我想渲染页面特定的标题,但它正在渲染布局标题。如果您看到我已经在 base-header-footer 中使用 ,并在装饰页面中使用标题标签。请注意我正在使用 来扩展基本布局,我认为这就是问题所在。
      • 是的,您在顶级布局中使用 g:layoutTitle,但不要在中间布局中使用它。将 g:layoutTitle 放入 login-header-footer.gsp
      猜你喜欢
      • 2021-11-15
      • 1970-01-01
      • 2012-09-24
      • 2011-10-16
      • 2012-07-07
      • 2011-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多