Title tag on K8

Olivier Cozette asked on February 4, 2015 19:33

I use a handy function inside repeaters on K7, to populate meta tags on pages:

protected override void OnDataBinding(EventArgs e) {
// Set values in meta tags
CMS.DocumentEngine.DocumentContext.CurrentTitle = "Something";
CMS.DocumentEngine.DocumentContext.CurrentDescription =  "Something";
CMS.DocumentEngine.DocumentContext.CurrentKeyWords =  "Something";    


Now, on K8, it seems impossible to write the Title, while Description & KeyWords are giving the expected results... Any ideas what can be wrong with it ? I've tried with & without "pagetitle_orelse_name" on the site's Title's configuration, still not working. It feels like something is overriding my value, because I've added this line at the end of my function:

Response.Write("CurrentTitle " + CMS.DocumentEngine.DocumentContext.CurrentTitle + "<br>");

and this line shows the wanted value... so it is evaluated, but after that, something erases the value.

Correct Answer

Olivier Cozette answered on February 8, 2015 23:44

This one is working:

protected override void OnLoad(EventArgs e)
              Title = DataBinder.Eval(this.DataItem, "TITLE-FROM-DB").ToString();            
              Page.Title = Title;
0 votesVote for this answer Unmark Correct answer

Recent Answers

Brenden Kehren answered on February 5, 2015 00:58

Why would you use this in a repeater? It would change the current page title/description/key works for every item in the repeater. So ultimately, the last item in the repeater is what your properties will be set to unless you check the dataitemindex.

You can create macros within the metadata of the page or page type which can capture fields being rendered for the current page type. Try this in your metadata properties:

{%if(ClassName == "cms.blog" || ClassName == "cms.blogmonth"){"A Day in the Life of a Kentico Developer - "}else{""}@%}{%DocumentName@%} 
0 votesVote for this answer Mark as a Correct answer

Olivier Cozette answered on February 5, 2015 01:43

Thanks Brenden, but this I think is not the case here: we had to import a list of +10000's users. An SQL table. Not Kentico doc_types.

Data changes every day.

Those users, have an ID, a NAME, and a PHONE. Now, we have a page, ex: /users.aspx?ID=0001, and this page will use a repeater (select top 1), and will search for the name and the phone. I need the name to become the TITLE tag. It was working just fine on K7, now only for the Title tag, is not working anymore. But description and keywords are still working using my function. That's why it's weird.

Anyway, thanks a lot !

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 5, 2015 14:41

Then try placing your method in an OnInit method vs the databinding method. It's all about timing and the lifecyle could be too far along to capture what is needed.

0 votesVote for this answer Mark as a Correct answer

Olivier Cozette answered on February 5, 2015 17:04

No luck ;(

I've tryed all available methods.. but you're right, it should be something with the lifecyle. Maybe the masterpage overrides my values somewhere, because at the time my repeater is created, my values do exists (I can print them on my page), but then the rest of the page loads, and my Title meta tag is replaced with emptyness... I'll keep searching !

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.