In one of our Compound Page Templates, we need to provide an overview of all pages in a certain Structure Group, and show links to these pages. We use Page properties Title and PublishPath for this. Example:
var sgFilter = new OrganizationalItemItemsFilter(engine.GetSession())
{
ItemTypes = new List<ItemType> { ItemType.Page },
Recursive = false,
};
StructureGroup sg = (StructureGroup)engine.GetObject(sgWebdavURL);
foreach (Page page in sg.GetItems(sgFilter))
{
Logger.Debug("Page alphabet title = " + page.Title);
Logger.Debug("Page alphabet publishpath = " + page.PublishPath);
}
Where sgWebdavURL is a string that is filled from the page metadata.
However, page.PublishPath is always NULL! I expected GetItems() to retrieve fully loaded Page objects. Appearently that is not the case. However, the LoadState Enumeration documentation suggests that a property, that has not been loaded yet, will be populated Just-In-Time when it is accessed.
Why does page.PublishPath return NULL? Why is the page object not fully loaded when the property is accessed? We use SDL Tridion 2011 SP1 HR 1.
This seems similar to https://stackoverflow.com/questions/13071526/accessing-properties-of-tom-net-objects-when-passing-them-between-methods-after
To work around this, I explicitly load the full Page object:
Logger.Debug("Page load state = " + page.LoadState.ToString());
if (page.LoadState != LoadState.FullyLoaded)
{
page.Load(LoadFlags.None);
}
This is quite an expensive operation. However, in our case, the actual requirement is a bit more complex than shown in the example above. We only need the link to the index page (which has page title "index") so only for this one page, the Load() is executed.
This does not answer the question why the page object is not fully loaded automatically when the PublishPath property is accessed...