Umbraco Get Current Page in Partial View

This article describes how to get the CurrentPage of Umbraco in a partial view.

commit 544ebad · authored · 1 min read

Umbraco Get Current Page in Partial View

In my website, the header section is a partial view which basically contains the header menus. The menus initially were same for all the pages across my site but I thought to hide some menu in case the current page is not the homepage.

To do that, I needed to get the current page and check whether the current page is the homepage or not, in the header partial.

To get the current page in partial view,

@inherits UmbracoTemplatePage
@{
var currentPage = Umbraco.Content(umbraco.NodeFactory.Node.GetCurrent().Id);
}

And to check whether it is home page or not, I decided to compare against DocumentTypeAlias as shown below,

@if (currentPage.DocumentTypeAlias == "home")
{
// some code

And it works.

local graph · open full graph

"Umbraco Get Current Page in Partial View" is connected to the topics Umbraco, CMS and related to 6 other entries. Best Umbraco Packages Best Umbraco Packages Enable Click-Jacking Protection - Umbraco Enable Click-Jacking Protec… Sitefinity Development - Problems and Solutions Sitefinity Development - Pr… Sitefinity - Caching issue for pages with NO CACHING profile Sitefinity - Caching issue … Sitefinity - Read localized resource labels in MVC widget Sitefinity - Read localized… Sitefinity Rookie Guide : Get Users in a Custom Role Sitefinity Rookie Guide : G… Umbraco #umbraco CMS #cms Umbraco Get Current Page in Parti…

comments

loading discussion…