Copied to clipboard

Flag this post as spam?

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


  • AJS 31 posts 212 karma points
    Nov 23, 2015 @ 18:14
    AJS
    0

    Logo image only displaying on homepage and not any child pages

    Hi,

    Still trying to figure out Umbraco, so please forgive my naiveté.

    I am having a hard time trying to get my logo image to display on any other page besides the homepage.

    I know I must be doing something wrong with the razor markup...

    <a class="visible-lg" href="@home.Url">
    
                @{      
                        if (CurrentPage.HasValue("siteLogo")){                                         
                            var dynamicMediaItem = Umbraco.Media(CurrentPage.siteLogo);
                            <img src="@dynamicMediaItem.Url" alt="@dynamicMediaItem.Name"/>
                        }
                    }
    
    </a>
    

    I know that I am targeting the "Current Page;" however I can't get it to appear any other way. Am I supposed to integrate .AncestorOrSelf()?

    I also can't seem to get it to work with @home.siteLogo.

    I guess I am looking for the best way to display an image (from the media picker) on all pages of the site from the property "siteLogo" under my Home document type.

    Any help would be greatly appreciated.

    Thanks,

    Amanda

  • AJS 31 posts 212 karma points
    Nov 23, 2015 @ 19:12
    AJS
    100

    Alright, it seems I was able to solve the problem with this code:

    <a class="visible-lg" href="@home.Url">
    
    
                    @{      
                        if (@Umbraco.Field("siteLogo", recursive: true) != null){                                         
                            var dynamicMediaItem = Umbraco.Media(CurrentPage._siteLogo);
                            <img src="@dynamicMediaItem.Url" alt="@dynamicMediaItem.Name" class="center-block" />
                        }
                    }
    
    
    
        </a>
    

    It was just kind of a hunch with the recursive and != null parts that I put in, but I don't know exactly how/why it works (haha) but at least it works!

    If someone wants to step in and explain it, that would be great!

Please Sign in or register to post replies

Write your reply to:

Draft