Saturday, 5 July 2008

X3 How To Series: How to get content function properties on a page

Given a page or a page collection you may need to find a property which exists within a content function on that page (if that function has been added). An example is a news summary where the heading, date and summary are coming from properties within a body content x3 content function on the child pages.

Use bits of the code below as required for your specific needs.

foreach(PageData page in collection)
{
//Add Dropit.Extension.Controllers
if (PageDataManager.IsExtensionPage(page))
{

ExtensionPageData extPage = ExtensionPageData.Load(page.PageLink);
IList<ContentFunctionData> functions = extPage.GetAllContentFunctions(page.PageLink);

foreach (ContentFunctionData functionData in functions)
{

//functionData is lazy loaded.
functionData.Load();

//access each property by indexer
if (IsValue("Heading", functionData))
{
heading = functionData.Property[
"Heading"].ToString();
}

//OR

//iterate properties
foreach (PropertyData property in functionData.Property)
{
//do something with properties
}

}

}


}

No comments: