Get Meta Title combined with Kentico settings for page via API

Tomasz Czado asked on March 19, 2018 10:32

Hi,

how can I get title for the page, that will not be just a DocumentName or something similar but will be combined with Kentico settings (Page title format, Page title prefix)? The only object I have is TreeNode.

Recent Answers


Dragoljub Ilic answered on March 19, 2018 11:40

Hi Tomasz,

I don't know is it possible to resolve macro from page title format setting (probably it is with additional customization), but if you know what format is you can retrieve prefix from settings with something like this: SettingsKeyInfoProvider.GetValue($"{SiteContext.CurrentSiteName}.CMSPageTitlePrefix");

And then take page title or document name from TreeNode object.

Best regards, Dragoljub

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on March 19, 2018 12:05 (last edited on March 19, 2018 12:14)

Assuming you want to get Meta Page information :

  // Gets an existing page in the "en-us" culture
    TreeNode page = tree.SelectNodes()
        .Path("/Articles/Coffee-Beverages-Explained")
        .OnCurrentSite()
        .Culture("en-us")
        .FirstObject;

    var metaPageTitle = page.DocumentPageTitle;
    var metaPageDescription = page.DocumentPageDescription;
    var metaPageKeywords = page.DocumentPageKeyWords;

They should be resolved i.e. should not get {%prefix%} - {%pagetitle_orelse_name%}, but if you do get it then just call macro resolver

var metaPageTitle = MacroResolver.Resolve(page.DocumentPageTitle);

1 votesVote for this answer Mark as a Correct answer

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