Question

I have a page in Kentico that displays data from a custom table. One of the custom table fields is page title, and I can't figure out how to display the page title field in the...

<title></title>

...tags

The closest thing I can get to it is displaying part of the uri as the title, so /promo/page-title will create a title of

<title>page-title</title>

Wich is less than desirable for three reasons:

  1. /promo/pAgE-TItle will display the title as pAgE-TItle
  2. the dashes are still there from the url
  3. The text from the uri is actually just a slug that represents the data in the custom table (a field named programkey) and is Not always the same as the actual title of the data

(EDIT)

Ok thanks to Raymond, and a bit of fumbling around, this is what I found works (posted in a custom table transformation):

    <script runat="server"> 
        private string Title { get; set;}
        private string Description { get; set;}
        private string Keywords { get; set;}
        protected override void OnDataBinding(EventArgs e)
        {
            base.OnDataBinding(e);
            // Get values from custom table
            Title = DataBinder.Eval(this.DataItem, "seo_title").ToString();
            Description = DataBinder.Eval(this.DataItem, "seo_desc").ToString();
            Keywords = DataBinder.Eval(this.DataItem, "seo_keywords").ToString();
            // Set values in meta tags
            CMSContext.CurrentTitle = Title;
            CMSContext.CurrentDescription = Description;
            CMSContext.CurrentKeyWords = Keywords;
        }
    </script>
Was it helpful?

Solution 2

This should do the trick:

  CMSContext.CurrentTitle = "asdasd";

OTHER TIPS

You can also create a custom macro in which you will use the API to get the custom table data. Then, use this macro in the page title/metadata settings

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top