Adding meta tags to News Items using script tags in widget template
I'm trying to add meta tags to News items using script tags in the widget template.
We are currently doing this for blog posts. There's a script tag that pulls a blog post's Title, Summary and ImageURL and creates Open Graph tags using them. I'm trying to replicate this code for News Items. I need help with the following:
1) What assemblies do I need to reference?
2) How should I write the method, what arguments should I use?
3) How should I define var data?
Here is the blog post widget code I'm trying to replicate and translate for News Item
BLOG
<%@ Control Language="C#" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Blogs.Model" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Model" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Taxonomies" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Taxonomies.Model" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.OpenAccess" Assembly="Telerik.Sitefinity" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Modules.Comments.Web.UI.Frontend" TagPrefix="comments" %>
<%@ Import Namespace="Telerik.Sitefinity" %>
<%@ Import Namespace="Telerik.Sitefinity.Modules.Comments" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Security" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Security.Model" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Security.Claims" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Modules.Libraries" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Modules.GenericContent" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.GenericContent.Model" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Services" Assembly="Telerik.Sitefinity" %>
<script type="C#" runat="server">
protected void Page_Load(object sender, EventArgs e)
protected void Repeater_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)
var data = ((RadListViewDataItem)e.Item).DataItem as BlogPost;
var placeholder = e.Item.FindControl("tags") as Literal;
placeholder.Text = RenderFlatTaxaAsLink(data, "Tags");
HtmlMeta metaImage = new HtmlMeta();
metaImage.Attributes.Add("property", "og:image");
metaImage.Name = "og:image";
metaImage.Content = data.GetValue("ImageURL").ToString();
this.Page.Header.Controls.Add(metaImage);
HtmlMeta metaTitle = new HtmlMeta();
metaTitle.Attributes.Add("property", "og:title");
metaTitle.Name = "og:title";
metaTitle.Content = data.GetValue("Title").ToString() + " | APICS Blog";
this.Page.Header.Controls.Add(metaTitle);
HtmlMeta metaDescription = new HtmlMeta();
metaDescription.Attributes.Add("property", "og:description");
metaDescription.Name = "og:description";
metaDescription.Content = data.GetValue("Description").ToString();
this.Page.Header.Controls.Add(metaDescription);