header 中未显示元标记
meta tags not showing in header
我正在使用 umbraco 并且还使用母版页功能。我有一个包含多个模板的母版页,因为它是 children.
我将以下元标记放入其中一个 children(模板)的 <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>
然而,由于母版页中的 child 正在母版页中呈现 body,它根本不会显示在头部。取而代之的是来自我的母版页的显示(它应该将两者结合起来?)
我不能简单地将这些标签放在我的母版页中,因为我需要为每个页面单独放置图像,只有在页面的每个模板中单独放置元标记才能做到这一点。
我也在官方论坛 our.umbraco 上问过这个问题,但他们没有像这个论坛那样活跃的社区。 https://our.umbraco.org/forum/using-umbraco-and-getting-started/89674-meta-tags
如果你想从你的模板中注入一些东西到master中,你应该使用RenderSection
:
这是一个例子:
Master.cshtml:
<!DOCTYPE html>
<html>
<head>
...
@RenderSection("meta", required: false)
...
</head>
<body>
...
@RenderBody()
...
</body>
</html>
Template.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"/>
}
我正在使用 umbraco 并且还使用母版页功能。我有一个包含多个模板的母版页,因为它是 children.
我将以下元标记放入其中一个 children(模板)的 <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>
然而,由于母版页中的 child 正在母版页中呈现 body,它根本不会显示在头部。取而代之的是来自我的母版页的显示(它应该将两者结合起来?)
我不能简单地将这些标签放在我的母版页中,因为我需要为每个页面单独放置图像,只有在页面的每个模板中单独放置元标记才能做到这一点。
我也在官方论坛 our.umbraco 上问过这个问题,但他们没有像这个论坛那样活跃的社区。 https://our.umbraco.org/forum/using-umbraco-and-getting-started/89674-meta-tags
如果你想从你的模板中注入一些东西到master中,你应该使用RenderSection
:
这是一个例子:
Master.cshtml:
<!DOCTYPE html>
<html>
<head>
...
@RenderSection("meta", required: false)
...
</head>
<body>
...
@RenderBody()
...
</body>
</html>
Template.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"/>
}