This is a modified version of the existing SitePageData page type class in the
Alloy templates.
|
using System.ComponentModel.DataAnnotations;
using System.Linq;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EPiServer.Framework.Localization;
using EPiServer.ServiceLocation;
using EPiServer.Templates.Alloy.Models.Properties;
using EPiServer.Web;
namespace EPiServer.Templates.Alloy.Models.Pages
{
public abstract class SitePageData : EPiServer.Core.PageData
{
|
Find's CMS integration adds a default value for SearchSection by including
an extension method named SearchSection. That method returns the PageName
of the page's ancestor which resides below the start page. In the Alloy
templates it may be more suitable to determine their section the same way
as is done in the site's footer (see Footer.aspx). Here we override the
default SearchSection implementation by adding a property with the same name
that maps each page's search section to the same "section" as in the footer.
|
[Ignore]
public virtual string SearchSection
{
get
{
if(GetType() == typeof(ProductPage))
{
return PageName;
}
var contentRepository = ServiceLocator.Current
.GetInstance<IContentRepository>();
var startPage = contentRepository.Get<StartPage>(ContentReference.StartPage);
var ancestors = contentRepository.GetAncestors(PageLink).ToList();
var productAncestor = ancestors.OfType<ProductPage>().FirstOrDefault();
if(productAncestor != null)
{
return productAncestor.PageName;
}
if(ancestors.Any(x => x.ContentLink
.CompareToIgnoreWorkID(startPage.CompanyInformationPageLink)))
{
return LocalizationService.Current.GetString("/footer/company");
}
if(ancestors.Any(x => x.ContentLink
.CompareToIgnoreWorkID(startPage.NewsPageLink)))
{
return LocalizationService.Current.GetString("/footer/news");
}
if(ancestors.Any(x => x.ContentLink
.CompareToIgnoreWorkID(startPage.CustomerZonePageLink)))
{
return LocalizationService.Current.GetString("/footer/customerzone");
}
return null;
}
}
/*Other properties that already exists in the Alloy templates */
}
}
|