Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Harry Stewart 15 posts 95 karma points
    Dec 16, 2016 @ 16:55
    Harry Stewart
    0

    How to find current page name from partial view

    I am creating a website in Umbraco and I need to get the current page's name from a partial view, could anyone help?

    Here's my code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    <h2 class="title" style="margin-bottom: 100px;">@CurrentPage.GetPropertyValue("title")</h2>
    @if(CurrentPage.Name.ToLower() == "home")
    {
    <div class="grid-2">
        <h4 class="subtitle">Loader-1</h4>
        <div class="loader-1"></div>
    </div>
    <div class="grid-2">
        <h4 class="subtitle">Loader-2</h4>
        <div class="loader-2"></div>
    </div>
    <div class="grid-2">
        <h4 class="subtitle">Loader-3</h4>
        <div class="loader-3"></div>
    </div>
    <div class="grid-2">
        <h4 class="subtitle">Loader-4</h4>
        <div class="loader-4"></div>
        </div>
    <div class="grid-2">
        <h4 class="subtitle">Loader-5</h4>
        <div class="loader-5"></div>
    </div>
    <div class="grid-2">
        <h4 class="subtitle">Loader-6</h4>
        <div class="loader-6"></div>
    </div>
    <div class="grid-12" style="margin-top: 100px;">
        <a href="@Umbraco.Content(CurrentPage.GetPropertyValue("pageUrl")).Url" class="button-1 hover-3">View More</a>
    </div>
    } else {
        <div class="grid-2">
            <h4 class="subtitle">Loader-1</h4>
            <div class="loader-1"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-2</h4>
            <div class="loader-2"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-3</h4>
            <div class="loader-3"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-4</h4>
            <div class="loader-4"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-5</h4>
            <div class="loader-5"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-6</h4>
            <div class="loader-6"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-7</h4>
            <div class="loader-7"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-8</h4>
            <div class="loader-8"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-9</h4>
            <div class="loader-9"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-10</h4>
            <div class="loader-10"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-11</h4>
            <div class="loader-11"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-12</h4>
            <div class="loader-12"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-13</h4>
            <div class="loader-13"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-14</h4>
            <div class="loader-14"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-15</h4>
            <div class="loader-15"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-16</h4>
            <div class="loader-16"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-17</h4>
            <div class="loader-17"></div>
        </div>
        <div class="grid-2">
            <h4 class="subtitle">Loader-18</h4>
            <div class="loader-18"></div>
        </div>
    }
    

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Dec 16, 2016 @ 23:08
    Alex Skrypnyk
    1

    Hi Harry,

    Try to use :

    CurrentPage.Name
    

    Thanks

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Dec 17, 2016 @ 11:42
    Dennis Adolfi
    2

    Or if you don't want dynamics, go:

    @Model.Content.Name.

  • Harry Stewart 15 posts 95 karma points
    Dec 17, 2016 @ 18:12
    Harry Stewart
    0

    Thanks for the suggestions but I'm using a package called 'Doctype Grid Editor' which allows you to use partials as grid options and created doctype objects as a datatype and the partial is in the grid.

  • M N 125 posts 212 karma points
    Aug 23, 2017 @ 19:22
    M N
    3

    Ran into this myself - Nested Content, in general, you are rendering manually - so I was previously passing the CurrentPage in from higher up (CurrentPage.Content for IPublishedContent)

    However, just recently found that this is stored in the UmbracoContext.

    You can do something like this from your Partials, works great with Doctype Grid Editor

    IPublishedContent CurrentPage = UmbracoContext.Current.PublishedContentRequest.PublishedContent;
    

    Hope that helps, -Marc

  • jake williamson 207 posts 873 karma points
    Nov 08, 2018 @ 14:13
    jake williamson
    1

    just found this post and it got me out of a bind - nice ;)

    i've ended up add this to our nested content models:

    public IPublishedContent CurrentPage => UmbracoContext.Current.PublishedContentRequest.PublishedContent;
    

    works a treat!

  • Denford 132 posts 323 karma points
    Jan 13, 2020 @ 12:33
    Denford
    4

    in v8 its shorter method

    var currentPage = UmbracoContext.PublishedRequest.PublishedContent;
    
Please Sign in or register to post replies

Write your reply to:

Draft