Alexander Staroselsky
Alexander Staroselsky

Reputation: 38757

Kentico Document Get Page Meta Data Custom Page Type

When trying to retrieve DocumentPageTitle and DocumentPageDescription using GetStringValue() on a custom page type TreeNode, the result is always coming back as the default value (in this case an empty string) passed into the method.

I'm able to successfully retrieve other column values as well as standard document properties such as DocumentName, DocumentID and AbsoluteURL, but not the document meta properties.

The respective fields in the Meta tab of document/page do have values and are being successfully rendered in the by default such as <meta name="description" content=".." />

// returns empty string
string documentPageDescription = DocumentContext.CurrentDocument.GetString("DocumentPageDescription", string.Empty);

// returns empty string
TreeNode document = parameters[0] as TreeNode;
string documentPageDescription = document.GetStringValue("DocumentPageDescription", string.Empty);

I've tried setting option Inherits fields from page type to "Page (menu item)", but that did not help.

Does the custom page type need to inherit from something specifically or have a specific setting activated to access these values? Or if what I think is a TreeNode in fact isn't, how could I get the TreeNode from this object that has the properties listed before available?

Thank you for any help you can provide.

Upvotes: 0

Views: 734

Answers (3)

Alexander Staroselsky
Alexander Staroselsky

Reputation: 38757

The DocumentPageTitle and DocumentPageDescription were coming back as null when the custom page type document/page was inheriting from parent/global values.

I was able to use the following to get the properties when not inheriting, while falling back to the parent value when inheriting was taking place:

string documentPageTitle = document.GetStringValue("DocumentPageTitle", DocumentContext.CurrentTitle);

This approach came from the following issue on Kentico DevNet.

Thank you for your help and suggestions, it's appreciated.

Upvotes: 0

Rui
Rui

Reputation: 494

Two things to check, one, are you sure the meta data is available on the page you are pulling? Two, is your API actually pulling all the data for that page?

I've used these in my test and both returned the metadata.

var page = DocumentHelper.GetDocuments().Path("/Articles/Coffee-Beverages-Explained").FirstObject;
Response.Write(page.GetStringValue("DocumentPageDescription", string.Empty));

TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
TreeNode tn = tree.SelectNodes().OnCurrentSite().Path("/Articles/Coffee-Beverages-Explained").FirstObject;
Response.Write(tn.GetStringValue("DocumentPageDescription", string.Empty));

Upvotes: 0

Peter Mogilnitski
Peter Mogilnitski

Reputation: 998

ValidationHelper.GetString(CMS.DocumentEngine.DocumentContext.CurrentDocument.GetValue("DocumentPageDescription"), string.Empty)

Upvotes: 1

Related Questions