When building a website where we share controls/blocks between different layouts dynamically, there will be situations when we need custom logic to determine the control layout or template the current page uses. One very common example is being able to check if a control is on the homepage, or not. In today's tutorial, I'm going to cover a few Sitecore API's to help us achieve that.
var homepage = Sitecore.Context.Database.GetItem(Sitecore.Context.Site.StartPath);
var isHomepage = homepage.ID.Equals(Sitecore.Context.Item.ID))
<site name="website" virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content" startItem="/home" database="web" domain="extranet" allowDebug="true" cacheHtml="true" htmlCacheSize="10MB" registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="5MB" filteredItemsCacheSize="2MB" enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false" />
var isHomepage = Sitecore.Context.Item.Paths.FullPath.Equals(
var isHomepage = Sitecore.Context.Item.TemplateName == "Homepage";
var isHomepage = Sitecore.Context.Item.TemplateID == "6275c3e8-4d58-4f23-af6a-5a18863a24cf";
Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge