How To Check if The Current Sitecore Page Is the Homepage? 

As a Sitecore developer definitely we will come across this scenario where we want to go to the root item that is the home item. In certain situation, we may come across where we need to check if the current Sitecore page is homepage. In this tutorial let’s look at How To Check if The Current Sitecore Page Is the Homepage.

How To Check if The Current Sitecore Page Is the Homepage?

The easiest way is to write a simple code and see if the current URL is pointing to the home page URL.

This first line is to fetch the home item in the Sitecore and the second line actually used to compare if the current page or current item is a home item or not. It returns true if the item is a home page else false.

We always set the default path of the home item in the web.config and hence the code Sitecore.Context.Site.StartPath always returns home item.

Another way of verifying if the current page is homepage or not is by comparing the current item’s full path with the home items path i.e., start path.

 

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *