Copied to clipboard

Flag this post as spam?

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


  • Naufil 23 posts 114 karma points
    Jul 13, 2018 @ 10:27
    Naufil
    0

    Master page not loading in child content

    I have a dynamic logo which is in master page, it's load in Parent page(Home) but doesn't load in child page.

    Please help..!!

    Thank-you..!!

  • Rune Hem Strand 147 posts 911 karma points hq c-trib
    Jul 13, 2018 @ 10:38
    Rune Hem Strand
    0

    Hi Naufil,

    a little tricky to answer without more information. But it could be that the path for the image is relative.

    <img src="images/logo.png" class="logo" /> 
    

    will load at the root / of your site but if you go to a child page ie. /about-us/ it will fail as it is trying to load an image from
    /about-us/images/logo.png.

    If you add a forward slash / in front of the url like this

    <img src="/images/logo.png" class="logo" />
    

    it will always go to the root and then the images folder.

    Hope that helps

    /Rune

  • Naufil 23 posts 114 karma points
    Jul 13, 2018 @ 10:46
    Naufil
    0

    Thanks Rune but i'm using dynamic image.

    From this way,

    @{
                        var typedMediaPickerSingle = Model.Content.GetPropertyValue<IPublishedContent>("Logo");
                        if (typedMediaPickerSingle != null)
                        {
                            <a href="#"><img src="@typedMediaPickerSingle.Url" alt="@typedMediaPickerSingle.GetPropertyValue("alt")" class="menu-logo-bottom img-responsive"/></a>
                        }
                    }  
    
  • Rune Hem Strand 147 posts 911 karma points hq c-trib
    Jul 13, 2018 @ 10:48
    Rune Hem Strand
    0

    Mkay 🤔

    Where is the media picker located? On the root node?

  • Naufil 23 posts 114 karma points
    Jul 13, 2018 @ 10:49
    Naufil
    0

    Yes

  • Rune Hem Strand 147 posts 911 karma points hq c-trib
    Jul 13, 2018 @ 10:59
    Rune Hem Strand
    101

    Alrighty, tehn I think that's where the issue is.

    When you use Model.Content you're working with IPublishedContent of the current page. So when you´re on the root node the Logo property will be on the current page model. When you're on a child node it will not be there, as the current page model is that of the child node.

    What you need to do, if this is the case, is to get the root node and the get the property from there. There is a helper method on IPublishedContent for this:

     @{
        var typedMediaPickerSingle = Model.Content.Site().GetPropertyValue<IPublishedContent>("Logo");
        if (typedMediaPickerSingle != null)
        {
            <a href="#"><img src="@typedMediaPickerSingle.Url" alt="@typedMediaPickerSingle.GetPropertyValue("alt")" class="menu-logo-bottom img-responsive"/></a>
        }
     }  
    

    This will get you the root node no matter where you are in the content tree and you can get the property 😊

    Pro tip: If you need to get the root node multiple times in a template save in a variable and call that.

    @inherits UmbracoTemplatePage
    @{
       Layout = null;
    
       var root = Model.Content.Site();
    }
    
    ...
    
    @{
        var typedMediaPickerSingle = root.GetPropertyValue<IPublishedContent>("Logo");
        if (typedMediaPickerSingle != null)
        {
            <a href="#"><img src="@typedMediaPickerSingle.Url" alt="@typedMediaPickerSingle.GetPropertyValue("alt")" class="menu-logo-bottom img-responsive"/></a>
        }
     } 
    

    Otherwise you'll be creaing IPublishedContent objects everytime you call it.

  • Naufil 23 posts 114 karma points
    Jul 13, 2018 @ 11:03
    Naufil
    1

    Wow, it's work like charm. Big Thanks a lot Rune. :)

  • Rune Hem Strand 147 posts 911 karma points hq c-trib
    Jul 13, 2018 @ 11:03
    Rune Hem Strand
    0

    You're so very welcome :)

  • Rune Hem Strand 147 posts 911 karma points hq c-trib
    Jul 13, 2018 @ 11:05
    Rune Hem Strand
    0

    You're so very welcome!

    Remember to mark the answer as a solution if it works.

    🙌

Please Sign in or register to post replies

Write your reply to:

Draft