Copied to clipboard

Flag this post as spam?

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


  • Mike Dorst 53 posts 215 karma points
    Oct 30, 2017 @ 11:48
    Mike Dorst
    0

    Hiding partial view on specific pages

    Hello,

    I am currently using a partial view to create breadcrumbs, the partial views looks like this:

    <div class="breadcrumb" itemprop="breadcrumb">
    @foreach (var level in Model.Content.Ancestors().Where("Visible").OrderBy("Level")) {
        <a class="BreadCrumb" href="@level.Url">@level.Name</a> <span>&gt;</span>
    }
    @CurrentPage.Name</div>
    

    I am displaying the partial view on my master page using the following code:

     <div class="BreadCrumbNav">@Html.Partial("BreadCrumb")</div>
    

    It's put in the nav bar which makes the breadcrumbs visible on every site. However I do not want to display it on the home page. So my question is: Is there a way to hide the partial view on the homepage but being able to display it on the rest of the pages?

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Oct 30, 2017 @ 11:57
    Alex Skrypnyk
    102

    Hi Mike

    Please, change code of the view to this one:

    @if (!Umbraco.AssignedContentItem.DocumentTypeAlias.Equals("homePage"))
            {
                <div class="breadcrumb" itemprop="breadcrumb">
                    @foreach (var level in Model.Content.Ancestors().Where("Visible").OrderBy("Level"))
                    {
                        <a class="BreadCrumb" href="@level.Url">@level.Name</a>
                        <span>&gt;</span>
                    }
                    @CurrentPage.Name
                </div>
            }
    

    Replace, please, "homePage" with your home page document type alias.

    Thanks,

    Alex

  • Mike Dorst 53 posts 215 karma points
    Oct 30, 2017 @ 12:01
    Mike Dorst
    0

    Thank you! That did the job. Is there any way I can change the first node though? It currently looks like this:

    Website > 1st page > 2nd page etc

    This is because the main level is called "Website"

    Is there a possibility to change this to "Home" without changing the node name from "Website" to "Home"?

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Oct 30, 2017 @ 12:19
    Alex Skrypnyk
    0

    Yes, of course, just like that:

    @if (!Umbraco.AssignedContentItem.DocumentTypeAlias.Equals("homePage"))
            {
                <div class="breadcrumb" itemprop="breadcrumb">
                    @foreach (var level in Model.Content.Ancestors().Where("Visible").OrderBy("Level"))
                    {
                        if (Umbraco.AssignedContentItem.DocumentTypeAlias.Equals("homePage"))
                        {
                            <a class="BreadCrumb" href="@level.Url">Home</a>
                        }
                        else
                        {
                            <a class="BreadCrumb" href="@level.Url">@level.Name</a>
                        }
                        <span>&gt;</span>
                    }
                    @CurrentPage.Name
                </div>
            }
    
  • Mike Dorst 53 posts 215 karma points
    Oct 30, 2017 @ 12:31
    Mike Dorst
    0

    That sadly doesn't work!

    The Alias of that page is literally "Website" so I have the following code:

    @if (!Umbraco.AssignedContentItem.DocumentTypeAlias.Equals("Home"))
        {
            <div class="breadcrumb" itemprop="breadcrumb">
                @foreach (var level in Model.Content.Ancestors().Where("Visible").OrderBy("Level"))
                {
                    if (Umbraco.AssignedContentItem.DocumentTypeAlias.Equals("Website"))
                    {
                        <a class="BreadCrumb" href="@level.Url">Home</a>
                    }
                    else
                    {
                        <a class="BreadCrumb" href="@level.Url">@level.Name</a>
                    }
                    <span>&gt;</span>
                }
                @CurrentPage.Name
            </div>
        }
    

    However it stays as "website" on the page and not as "home"

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Oct 30, 2017 @ 13:22
    Alex Skrypnyk
    0

    Hi Mike

    You have

    @if (!Umbraco.AssignedContentItem.DocumentTypeAlias.Equals("Home"))

    and

    if (Umbraco.AssignedContentItem.DocumentTypeAlias.Equals("Website"))

    in this code, so the error is in the first IF also, can it be?

    Thanks,

    Alex

  • Mike Dorst 53 posts 215 karma points
    Oct 30, 2017 @ 13:30
    Mike Dorst
    0

    I don't understand what you mean, sorry.

    The first IF is working fine as it hides the breadcrumb on my homepage. The second IF isn't working as it doesn't change the breadcrumb from "Website > 1st page > 2nd page" to "Home > 1st page > 2nd page"

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Oct 30, 2017 @ 13:37
    Alex Skrypnyk
    0

    Then your doctype alias is "Home", not "Website"

    and you have to use this statement:

    if (Umbraco.AssignedContentItem.DocumentTypeAlias.Equals("Home")) { Home } else { @level.Name }

  • Mike Dorst 53 posts 215 karma points
    Oct 30, 2017 @ 13:58
    Mike Dorst
    0

    It works, thanks!

Please Sign in or register to post replies

Write your reply to:

Draft