代码之家  ›  专栏  ›  技术社区  ›  Mik3NL

标题中未显示元标记

  •  1
  • Mik3NL  · 技术社区  · 7 年前

    我正在使用umbraco和母版页功能。我有一个母版页和几个模板,因为它的孩子。

    我在 <head> 其中一个子网站(模板)的链接,以便在facebook共享上获得正确的缩略图。

    <head>
        <meta property="og:type" content="website"> 
        <meta property="og:site_name" content="SITENAME">
        <meta property="og:title" content="Reports"/>
        <meta property="og:url" content="www.exameple.com"/>
        <meta property="og:image" content="http://via.placeholder.com/2000x2000"/>
    </head>
    

    然而,由于母版页中的子对象在母版页中呈现为其身体,因此它根本不会出现在头部。相反,将显示“来自我的母版页”(它应该将两者结合起来?)

    我不能简单地将这些标签放在我的母版页中,因为我需要每个页面都有单独的图像,只有在页面的每个模板中放置单独的元标签时才能完成。

    image image2

    我也在我们的网站上问了这个问题。umbraco是一个官方论坛,但他们没有一个如此活跃的社区。 https://our.umbraco.org/forum/using-umbraco-and-getting-started/89674-meta-tags

    1 回复  |  直到 7 年前
        1
  •  4
  •   Davor Zlotrg    7 年前

    您应该使用 RenderSection 如果要将模板中的内容注入master:

    以下是一个示例:

    主人cshtml:

    <!DOCTYPE html>
    <html> 
    <head>
        ...
        @RenderSection("meta", required: false)
        ...
    </head>
    <body>
        ...
        @RenderBody()
        ...
    </body>
    </html>
    

    样板cshtml

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @section meta
    {
        <meta property="og:type" content="website"> 
        <meta property="og:site_name" content="SITENAME">
        <meta property="og:title" content="Reports"/>
        <meta property="og:url" content="www.exameple.com"/>
        <meta property="og:image" content="http://via.placeholder.com/2000x2000"/>
    }