Copied to clipboard

Flag this post as spam?

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


  • Meni 272 posts 529 karma points
    Aug 31, 2023 @ 06:12
    Meni
    0

    Show logo / image on all pages

    Hi, I want to display a logo on all the pages.

    In my layout I have the following:

    <!-- Main Container -->
    <div class="container-fluid">
        <header>
            <div class="row">
                <div class="col-xl-3">
                    @await Umbraco.RenderMacroAsync("LogoHandler")
    
                </div>
    
                <div class="col-xl-9">
                </div>
            </div>
        </header>
    

    And this is the macro partial:

    @inherits Umbraco.Cms.Web.Common.Macros.PartialViewMacroPage
    @using Umbraco.Cms.Core.Services;
    @inject IContentService Services;
    
    @{
    if(Model.Content.HasValue("logo")){      
        var mediaItem = Model.Content.Value<IPublishedContent> 
               ("logo");
        var imageHeight = mediaItem.Value<int>("umbracoHeight");
        var imageWidth = mediaItem.Value<int>("umbracoWidth");
        <div style="padding: 20px 0 20px 5px;"><img src="@mediaItem.Url()" alt="@Model.Content.Value("photoAlt")" class="img-fluid" /></div>
      }
    }
    

    The problem is that the logo only shows on home page , like, in the root (www.mywebsite.net) and not in any other page in the website

    Because all on the other pages if(Model.Content.HasValue("logo")){ returns false.

    My question is: can I refer to a parent model? The page in the content tree for the layout is the parent page for the whole website. I guess for any other page it looks for the logo in the current model and not find it.

    So how do I make it in the code that in any other page than the home page it will look for the logo in the parent model?

    Thanks

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Aug 31, 2023 @ 07:22
    Huw Reddick
    100

    Hi Meni,

    IIRC you can use Model?.Content.Root().HasValue("logo")

  • Meni 272 posts 529 karma points
    Aug 31, 2023 @ 18:47
    Meni
    0

    Hi, I can try. Just a quick question before I try - will it cost resources to use the Root() method? (Like, in every page to go all the way to the root? Or it will give the root right away without any calculations?)

    Thanks

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Sep 01, 2023 @ 07:37
    Huw Reddick
    0

    It shouldn't no

  • Meni 272 posts 529 karma points
    Sep 06, 2023 @ 05:15
    Meni
    0

    ok, thank. It works.

    Thanks for your help.

Please Sign in or register to post replies

Write your reply to:

Draft