API to set page or cms.news Metadata for Page Title, and Page Description

David Pearson asked on October 8, 2015 20:58

I have a piece of code that will import news articles from Sitefinity to Kentico. I am attempting to set the Metadata Title, and description when I insert the article.

I set up the new article insert using TreeNode newNode = TreeNode.New("CMS.News", tree)

Once the new variable is created I assign values like this.
newNode.SetValue("NewsText", importArticle.Content)

For the tags I just do a newNode.DocumentTags = some list of tags.

I do not see a newNode.DocumentTitle or DocumentMetatagTitle or what every it could be.

How do I set the Metatag Page Title value and uncheck Page title Inherit via API? Want to do the same thing for Page Description. Attempting to set the Page Title to the Article Title, and the Page Description to Summary.

Could it be something similar to newNOde.SetValue("PageTitle", importArticle.Title) ?

Thanks David

Correct Answer

Brenden Kehren answered on October 9, 2015 15:43

You can also use macros in your document to auto populate them so you're not having to set them like this either. In the MetaData tab of the pages property you can set these macros. If you set it on the parent News page it will inherit all throughout the other pages. It's a much simpler solution than trying to set them each time a new news item is created. And it's more dynamic as well.

See the screenshot below: Image Text

You can also use page type specific values by simply checking if the CurrentDocument.ClassName == "cms.news" and if not then display nothing otherwise use {% NewsSummary %}

1 votesVote for this answer Unmark Correct answer

Recent Answers

Laura Frese answered on October 8, 2015 21:48

Within Kentico is an app that shows API examples. If you search for API examples from your Kentico desktop then go to Content Management > Tags you will see code for adding tags to pages. I will paste it here, but if you need more help with the API then you can check out more of those examples

private bool AddTagToDocument()
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

// Get the root document
TreeNode root = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/", null, true);

// Get tag group ID
TagGroupInfo updateGroup = TagGroupInfoProvider.GetTagGroupInfo("MyNewGroup", SiteContext.CurrentSiteID);

if ((root != null) && (updateGroup != null))
    // Add tag to document
    root.DocumentTags = "\"My New Tag\"";

    // Add tag to document
    root.DocumentTagGroupID = updateGroup.TagGroupID;

    // Update document

    return true;

return false;
0 votesVote for this answer Mark as a Correct answer

Laura Frese answered on October 8, 2015 22:18 (last edited on October 8, 2015 22:18)

Sorry, I browsed the question and mis-read it. you were on the right path:




0 votesVote for this answer Mark as a Correct answer

David Pearson answered on October 9, 2015 14:41

DocumentPageTitle does not compile CMS.DocumentEngine.TreeNode does not contain a definition for "DocumentpageTitle". Still digging into the API docs...

0 votesVote for this answer Mark as a Correct answer

David Pearson answered on October 9, 2015 15:05

Looks like I need to do a SetValue for a Column like newNode.SetValue("DocumentPageTitle", importArticle.Title).

Setting up a test now to see if this is the case.....

0 votesVote for this answer Mark as a Correct answer

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