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.
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.
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..!!
Hi Naufil,
a little tricky to answer without more information. But it could be that the path for the image is relative.
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 thisit will always go to the root and then the images folder.
Hope that helps
/Rune
Thanks Rune but i'm using dynamic image.
From this way,
Mkay 🤔
Where is the media picker located? On the root node?
Yes
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 theLogo
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:
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.
Otherwise you'll be creaing IPublishedContent objects everytime you call it.
Wow, it's work like charm. Big Thanks a lot Rune. :)
You're so very welcome :)
You're so very welcome!
Remember to mark the answer as a solution if it works.
🙌
is working on a reply...