@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?
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?)
Show logo / image on all pages
Hi, I want to display a logo on all the pages.
In my layout I have the following:
And this is the macro partial:
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
Hi Meni,
IIRC you can use
Model?.Content.Root().HasValue("logo")
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
It shouldn't no
ok, thank. It works.
Thanks for your help.
is working on a reply...