Accessing the first Component Presentations on a Page
You can access the first Component Presentation that has been placed on a Page from your code.
Package example
A package that has been processed by the default Template Building Block "Extract Components from Page" contains a package item called Components, which is an array. The first Component Presentation is the first element in the array.
// Get the Components array. ComponentsName is a constant for the string "Components".
Item componentsItem = package.GetByName(ComponentsName);
IComponentPresentationList componentPresentations =
ComponentPresentationList.FromXml(componentsItem.GetAsString());
Tridion.ContentManager.Templating.ComponentPresentation componentPresentation =
componentPresentations[1];
Content Manager example
A Page object in the Content Manager refers to an array of Component Presentations. The first Component Presentation is the first element in the array. In the following code example, the Page is retrieved by its Content Manager URI.
// Get the Component Presentations array for a specific Page
Page page = (Page) engine.GetSession().GetObject("tcm:13-73-64");
Tridion.ContentManager.CommunicationManagement.ComponentPresentation componentPresentation =
page.ComponentPresentations[1];
Note in these samples the difference between a Component Presentation in the package (class Tridion.ContentManager.Templating.ComponentPresentation) and a Component Presentation in the Content Manager (class Tridion.ContentManager.CommunicationManagement.ComponentPresentation).