Blog post as the page title
If I'm viewing a blog post, I'd like the title of the browser to be the title of the post...
How can I get that to work? Google seems to be indexing everything as "<Site> Blog" instead of something like "<Site> Blog <Post Title>" (or whatever)
Hi Steve,
One of the options here is using custom PageRouteHandler where you can get the PageData obeject you should set its HtmlTitle at runtime. Generally the Title is set though ObjectFactory and IoC, but the method cannot be overridden from there, so PageRouteHandler looks like more appropriate place.
Greetings,
Ivan Dimitrov
the Telerik team
Can we get a sample on how to do this? I'm having the same problem.
Hello adam,
Create a custom class that inherits from PageRouteHandler and override ProcessSiteNode method which is virtual. There get the page data and set the HtmlTitle
var siteMap = (SiteMapBase)node.Provider;
var pageSiteNode = (PageSiteNode)node;
var manager = PageManager.GetManager();
var pnode = manager.GetPageNode(pageSiteNode.Id);
pnode.Page.HtmlTitle = "test";
Best wishes,
Ivan Dimitrov
the Telerik team
Unfortunately this does not work with a "Redirecting Page" as, in the example, pnode.Page is null ...I am sure this has to do with the Redirecting page design, consider the following:
Hello Matthew ,
ProcessSiteNode is called when you open an item in a single mode.
Greetings,
Ivan Dimitrov
the Telerik team
Is this the only solution? Is there any other solution that doesn't involve creating custom classes and overriding methods?
Someting like this? http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/blog-post-page-title.aspx
It is amazing that this is not easier (not that doing the supplied example is all that hard) - it's just that it does not work in 100% of scenarios (redirect or group pages as a simple example)
This worked for me, getting the blog title during the itemdatabound event of the DetailsView and using PreRender to add to the page meta.
1) Create a custom widget project, add your references and add a class that inherits from Telerik.Sitefinity.Modules.Blogs.Web.UI.Public.DetailPostView.
namespace YourCompany.ModuleName [ControlTemplateInfo("BlogResources", "BlogsDetailViewFriendlyName", "BlogsTitle")] public class BlogDetailsView : Telerik.Sitefinity.Modules.Blogs.Web.UI.Public.DetailPostView private string strTitle = string.Empty; private string strDescription = string.Empty; private string strKeywords = string.Empty; public BlogDetailsView() public void DetailsView_ItemDataBound(object sender, RadListViewItemEventArgs e) if (e.Item.ItemType == RadListViewItemType.DataItem || e.Item.ItemType == RadListViewItemType.AlternatingItem) RadListViewDataItem item = e.Item as RadListViewDataItem; BlogPost bp = (BlogPost)item.DataItem; if(bp.Title != null) strTitle = bp.Title.ToString(); if (bp.Summary != null) strDescription = bp.Summary.ToString(); TaxonomyManager tm = new TaxonomyManager(); var keywords = new List<string>(); var cats = (Telerik.OpenAccess.TrackedList<System.Guid>)bp.GetValue("Category"); if (cats.Count > 0) foreach (Guid g in cats) HierarchicalTaxon ht = (HierarchicalTaxon)tm.GetTaxon(g); if (ht != null && !keywords.Contains(ht.Name.ToLowerInvariant())) keywords.Add(ht.Name.ToLowerInvariant()); var tags = (Telerik.OpenAccess.TrackedList<System.Guid>)bp.GetValue("Tags"); if (tags.Count > 0) foreach (Guid g in tags) FlatTaxon ft = (FlatTaxon)tm.GetTaxon(g); if (ft != null && !keywords.Contains(ft.Name.ToLowerInvariant())) keywords.Add(ft.Name.ToLowerInvariant()); if (keywords.Count > 0) StringBuilder sb = new StringBuilder(); foreach (string s in keywords) sb.Append(s); sb.Append(","); strKeywords = sb.ToString(); if (!String.IsNullOrEmpty(strKeywords)) strKeywords = strKeywords.Substring(0, strKeywords.Length - 1); protected override void InitializeControls(GenericContainer container, IContentViewDefinition definition) this.DetailsView.ItemDataBound += new EventHandler<RadListViewItemEventArgs>(this.DetailsView_ItemDataBound); base.InitializeControls(container, definition); protected override void OnPreRender(EventArgs e) if (string.IsNullOrEmpty(this.strTitle) == false) this.Page.Title = strTitle + " - " + Page.Title; if (string.IsNullOrEmpty(this.strDescription) == false) this.Page.MetaDescription = strDescription; if (string.IsNullOrEmpty(this.strKeywords) == false) if (!String.IsNullOrEmpty(this.Page.MetaKeywords)) this.Page.MetaKeywords += "," + strKeywords; else this.Page.MetaKeywords = strKeywords; base.OnPreRender(e);