Documentation Center

Accessing Page metadata

You can access the metadata of a Page from code.

Package example

A package in a Page Template contains a package item called Page. You can access the metadata fields as subvariables of the Page variable.

// In this example, the Page has two metadata fields: Author and ID
// (referring to an identifier specific to your organization).

string message = "Page"  + package.GetValue("Page.Title") + " was written by ";
// The ID field must be preceded by the string "Metadata" to distinguish it from
// the system field ID  (which refers to the Content Manager ID).
message +=
	package.GetValue("Page.Author") + " (ID is " + package.GetValue("Page.Metadata.ID" + ")");
log.Info(message);

Content Manager example

To get the metadata of a Page object in the Content Manager, use the ItemFields constructor as illustrated in this example.

// In this example, the Page has two metadata fields: Author and ID
// (referring to an identifier specific to your organization).

Page page = (Page) engine.GetSession().GetObject("tcm:13-73-64");
ItemFields metadataFields = new ItemFields(page.Metadata, page.MetadataSchema);
string message = "Page"  + page.Title + " was written by ";
message += metadataFields["Author"] + " (ID is) " + metadataFields["ID"];
log.Info(message);