Reputation: 401
I'm trying to add some meta tags from widget (/views/parts/ folder) that gets data from database outside of orchard. I need to put them to head section, and frankly I got no idea how to achieve that.
I tried:
using (Script.Head())
{
<meta property="description" content="ABC">
}
SetMeta("ABC", "description");
But none of these work :-(
Edit: our document.cshtml code:
@using Orchard.Mvc.Html;
@using Orchard.UI.Resources;
@{
RegisterLink(new LinkEntry { Type = "image/x-icon", Rel = "shortcut icon", Href = Url.Content("~/modules/orchard.themes/Content/orchard.ico") });
string title = Convert.ToString(Model.Title);
string siteName = Convert.ToString(WorkContext.CurrentSite.SiteName);
string classForPage = "static " + Html.ClassForPage();
}
<!DOCTYPE html>
<!--[if lt IE 7]>
<html lang="@WorkContext.CurrentCulture" class="@classForPage no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html lang="@WorkContext.CurrentCulture" class="@classForPage no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html lang="@WorkContext.CurrentCulture" class="@classForPage no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html lang="@WorkContext.CurrentCulture" class="@classForPage no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8" />
<title>@Html.Title(title, siteName)</title>
<meta name="viewport" content="width=device-width">
@{
Display(Model.Head);
}
<meta property="og:title" content="@Layout.Title - @Convert.ToString(WorkContext.CurrentSite.SiteName)">
<meta property="og:site_name" content="@Convert.ToString(WorkContext.CurrentSite.SiteName)">
<meta property="og:url" content="@Request.Url">
<meta property="og:type" content="article">
<script>(function(d){d.className="dyn"+d.className.substring(6,d.className.length);})(document.documentElement);</script>
</head>
<body>
@Display(Model.Body)
@Display(Model.Tail)
</body>
</html>
Does anybody know how to achieve that?
Upvotes: 0
Views: 1447
Reputation: 147
I used the following code in my layout.cshtml file before header tag and it worked.
@using (Script.Head())
{
<meta name="description" content="<your description>"/>
<meta name="keywords" content="<your keywords here>"/>
}
Enjoy!!!
Upvotes: 2
Reputation: 730
IResourceManager provides the necessary methods. For use it in view:
var resourceManager = WorkContext.Resolve<Orchard.UI.Resources.IResourceManager>();
resourceManager.SetMeta(new Orchard.UI.Resources.MetaEntry
{
Name = "description",
Content = "ABC"
});
But it can be also used in other places (e.g. part driver).
Edit using SetMeta("description", "ABC") in view give the same results.
Upvotes: 2