When you call Page.Data it tries to find a page by key in the current language/publication scope, if it is missing, it will throw an exception.
The valud is cached afterwards for the DataReference<Page> object it is called on.
The valud is cached afterwards for the DataReference<Page> object it is called on.
using System;
using System.Linq;
using System.Globalization;
using Composite.Core.Xml;
using Composite.Data;
using Composite.Data.Types;
namespace My.Data.Method
{
public static class InlineMethodFunction
{
public static string GetPageTitle(DataReference<IPage> Page)
{
if (Page == null)
{
return null;
}
using (var conn = new DataConnection(new CultureInfo("en-GB"))
{
Guid pageId = (Guid)Page.KeyValue
return conn.Get<IPage>().First(p => p.Id == pageId).Title;
// Alternative, but may not work if page.Data is already evaluated and cached for another version
// return page.Data.Title;
}
}
}
}