【问题标题】:How to add meta tags when using the play framework?使用play框架时如何添加meta标签?
【发布时间】:2014-05-30 12:42:27
【问题描述】:

我正在使用播放框架,并且有一个 main.scala.html 文件,该文件当前包含我每个网页的所有页眉和页脚信息。然后,我只为我创建的每个其他 html 页面引用 main.scala.html 页面。例如:

@main("enterprise") {

<!--=== Slider ===-->

<div class="layer_slider">
    <div id="layerslider-container-fw">        
        <div id="layerslider" style="width: 100%; height: 500px; margin: 0px auto; ">

正如您所见,@main("enterprise") {} 引用了主文件,而带有 {} 的所有内容都是企业页面的正文部分。但是,我想分别为我的每个页面添加元标记,并且想知道我应该如何做到这一点?我是否必须在要添加元数据的每个 html 页面中输入标签?

main.scala 头文件:

@(activeMenu: String, headParts: Html = Html(""))(content: Html)
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->  
<!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->  
<!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->  
<head>
    <title>SpryPoint | Smart Solutions for Smart Utilities</title>


    <!-- Meta -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

感谢您的建议。

【问题讨论】:

    标签: html scala playframework


    【解决方案1】:

    the template docmoreScripts 和 moreStyles 等效项 部分解决了此主题,例如:

    @headParts = {
        <meta name="description" content="Some description for this page only...">
    }
    
    @main("enetrprise", headParts){
       Html content here ...
    }
    

    编辑:所以您的 main.scala.html 看起来(根据您的附加评论)如下:

    @(activeMenu: String, headParts: Html = Html(""))(content: Html)
    <!DOCTYPE html>
    <html>
      <head>
        <title>@activeMenu</title>
        @headParts
      </head>
      <body>
        <section class="content">@content</section>
      </body>
    </html>
    

    【讨论】:

    • 我知道我来晚了,但我会在我的 main.scala.html 文件中添加什么来解决这个问题?目前我有:@(activeMenu: String)(content: Html)
    • 我刚刚添加了一些 main.scala.html 文件,以向您展示它目前的样子。已经有一个元描述的地方,但是它目前适用于每个页面,我试图具体到每个页面。
    猜你喜欢
    • 1970-01-01
    • 2012-03-22
    • 1970-01-01
    • 2011-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多