本文整理汇总了C#中SitecoreContext.GetHomeItem方法的典型用法代码示例。如果您正苦于以下问题:C# SitecoreContext.GetHomeItem方法的具体用法?C# SitecoreContext.GetHomeItem怎么用?C# SitecoreContext.GetHomeItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SitecoreContext
的用法示例。
在下文中一共展示了SitecoreContext.GetHomeItem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
/// <summary>
/// Handles the Load event of the Page control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void Page_Load(object sender, EventArgs e)
{
ISitecoreContext context = new SitecoreContext();
BasePageModel = context.GetCurrentItem<BasePageModel>();
HomeModel = context.GetHomeItem<HomeModel>();
LoadMetaData();
RegisterGoogleAnalyticsScript();
if (BasePageModel.Id == HomeModel.Id)
{
body.Attributes.Add("class", "homepage");
}
}
示例2: GetHomeItem_ReturnsHomeItem
public void GetHomeItem_ReturnsHomeItem()
{
//Assign
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
var doc = new XmlDocument();
doc.LoadXml("<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />");
Sitecore.Context.Site = new SiteContext(
new SiteInfo(
doc.FirstChild
)
);
//Sitecore.Context.Site = Sitecore.Configuration.Factory.GetSite("GetHomeItem");
var scContext = new SitecoreContext();
var target1 = db.GetItem("/sitecore/content/Tests/SitecoreContext/GetHomeItem/Target1");
//Act
var result = scContext.GetHomeItem<StubClass>();
//Assert
Assert.AreEqual(target1.ID, result.Id);
}
示例3: GetHomeItem_ReturnsHomeItem
public void GetHomeItem_ReturnsHomeItem()
{
//Assign
using (Db database = new Db
{
new Sitecore.FakeDb.DbItem("Target")
})
{
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass)));
var doc = new XmlDocument();
doc.LoadXml(
"<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content' startItem='/Target' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />");
Sitecore.Context.Site = new SiteContext(
new SiteInfo(
doc.FirstChild
)
);
//Sitecore.Context.Site = Sitecore.Configuration.Factory.GetSite("GetHomeItem");
using (new SiteContextSwitcher(new SiteContext(new SiteInfo(
doc.FirstChild
))))
{
var scContext = new SitecoreContext();
var target1 = database.GetItem("/sitecore/content/Target");
//Act
var result = scContext.GetHomeItem<StubClass>();
//Assert
Assert.AreEqual(target1.ID, result.Id);
}
}
}