Copied to clipboard

Flag this post as spam?

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


  • Matt 358 posts 841 karma points
    Aug 23, 2022 @ 09:03
    Matt
    0

    Get home property from master template

    Hi,

    So I have the following template layout

    • Master
      1. Home

    If I have a property field in Home, how can I render this in the master template?

    Cheers

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Aug 23, 2022 @ 13:38
    Huw Reddick
    0

    why would you want to render it in the main template exactly?

    The main template should be simply that, a scaffolding template.

    you can do this to get a reference to your home page (or something similar)

    var home = Umbraco.ContentAtRoot().Where(c=>c.ContentType.Alias == "home")
    
  • Matt 358 posts 841 karma points
    Aug 25, 2022 @ 07:18
    Matt
    0

    Hi,

    I want a pop up message to appear on every single page.

    This is what I have.

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @using Umbraco.Web.Models
    
    
    @{
    
    
        var home = Umbraco.ContentAtRoot().Where(c=>c.ContentType.Alias == "home");
    }
    
    
    
                               @if (!Model.Value<bool>("hidePopUp"))
    
    {
       <div class="bts-popup" role="alert">
        <div class="bts-popup-container">
          <p>@Model.Value("popUpText")</p>
    
            <a href="#0" class="bts-popup-close img-replace">Close</a>
        </div>
    </div>
    }
    

    But it only seems to work on home page, none of the other pages.

    Cheers

  • Mike Chambers 636 posts 1253 karma points c-trib
    Aug 26, 2022 @ 08:37
    Mike Chambers
    0
    @if (!home.Value<bool>("hidePopUp"))
    
    @home.Value("popUpText")
    

    Depending on if your hidePopUp is on the home node.. or if it's on your pages then revert back to Model

  • Matt 358 posts 841 karma points
    Aug 26, 2022 @ 08:45
    Matt
    0

    Hi Mike,

    Thanks for your reply.

    I can confirm that hidePopUp is on the home node.

    I'm getting this error now.

    > Compiler Error Message: CS1929: 'IEnumerable<IPublishedContent>' does
    > not contain a definition for 'Value' and the best extension method
    > overload 'PublishedElementExtensions.Value<bool>(IPublishedElement,
    > string, string, string, Fallback, bool)' requires a receiver of type
    > 'IPublishedElement'
    

    Thanks again.

    Matt

  • Mike Chambers 636 posts 1253 karma points c-trib
    Aug 26, 2022 @ 09:05
    Mike Chambers
    0

    Sorry just glanced

    Umbraco.ContentAtRoot().Where(c=>c.ContentType.Alias == "home").FirstOrDefault() and then check for null before using.

    Or you can do Model.Root() to get the node at Level 1 in the current pages ancestors. Which is you home node too.

    https://our.umbraco.com/Documentation/Reference/Querying/UmbracoHelper/index-v8#contentatroot

Please Sign in or register to post replies

Write your reply to:

Draft