Copied to clipboard

Flag this post as spam?

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


  • Aspargeus 12 posts 102 karma points
    Oct 12, 2020 @ 14:52
    Aspargeus
    0

    Hide master template element on certain page

    Hi. I'm pretty new to Umbraco and Razor.

    In my master template I have a scroll-to-top button in the lower right corner, which of course shows up on all pages with the master template.

    There is one specific page, in which I don't want the button to show, but I still want to use the master template for that page.

    What is the simplest way to achieve this? Some sort of check or just to make a new master template for that page without the button?

    Thanks.

  • Amir Khan 1282 posts 2739 karma points
    Oct 12, 2020 @ 15:57
    Amir Khan
    0

    You could do an if check for the ID of the page you want the button excluded from like this:

    @if(!CurrentPage.IsDescendantOrSelf(Umbraco.Content(id of your page you want the button excluded from))) {
    put your scroll button here}
    
  • Aspargeus 12 posts 102 karma points
    Oct 12, 2020 @ 17:01
    Aspargeus
    0

    Yeah, I guess that would probably be the easiest way of doing it.

    My only issue with that, is that I'm working locally and then pushing to Umbraco Cloud and I believe IDs are different between environments.

    But I guess I could just use the ID of the page on Cloud even though it wouldn't show correctly on my local version.

  • Amir Khan 1282 posts 2739 karma points
    Oct 12, 2020 @ 17:10
    Amir Khan
    0

    That's a good point. A safer way would be to add a checkbox to the document type called "hide scroll button" or something and check for that, would that be an option for you?

  • Aspargeus 12 posts 102 karma points
    Oct 13, 2020 @ 08:28
    Aspargeus
    0

    The solution I've implemented now, is just getting the URL of the current page and if that matches the URL of the page in question, then the button shouldn't show.

    Would it maybe be cleaner to put a checkbox on the doc type, like you suggested? How exactly would you implement that?

  • Amir Khan 1282 posts 2739 karma points
    Oct 13, 2020 @ 12:46
    Amir Khan
    0

    It would be more reliable, incase the url changes, and also you could use it on other pages in the future.

    You could go to your document type for the page, or an inherited one via a composition, like we have an SEO and Navigation doctype that is inherited on all of our pages, then add a property to that document type called "Hide Scroll Arrow" of type checkbox or true / false depending on your version and in your template render it using this: https://our.umbraco.com/documentation/getting-started/backoffice/property-editors/built-in-property-editors/true-false/

Please Sign in or register to post replies

Write your reply to:

Draft