I'm pretty new with Umbraco and now i've got the following question;
People can set a header/hero image, if they don't i got a fallback (code below). But if it's a sublevel i want it to take a look at his parent first and show that image (if it's available) before it shows the fallback.
How can i do this?
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var image = Model.Content.GetPropertyValue
@if (image != null)
{
var parent_image = Model.Content.GetPropertyValue
Please remember ParentHero should be replaced with the alias you used for the image property in the parent. I highly recommend you to use a code editor so that you can see semantic errors before previewing your changes.
Retrieve an image from a parent
Hello everyone,
I'm pretty new with Umbraco and now i've got the following question;
People can set a header/hero image, if they don't i got a fallback (code below). But if it's a sublevel i want it to take a look at his parent first and show that image (if it's available) before it shows the fallback. How can i do this?
Hi Peter,
I'm not sure if you're using strong typed models, but if you don't and your view looks like:
@inherits Umbraco.Web.Mvc.UmbracoViewPage
in the top, then you just do @Model.Parent. Are you using a code editor or are you just using the Umbraco Backoffice?
If you use Visual Studio, even with the website running you can just help yourself with Intellisense.
Happy coding!
Hi,
I'm using the backoffice. My complete code looks like this:
Something like this you could try:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ var image = Model.Content.GetPropertyValue
Please remember ParentHero should be replaced with the alias you used for the image property in the parent. I highly recommend you to use a code editor so that you can see semantic errors before previewing your changes.
Hi Peter,
If heroImage property is same on the parent page then you can use recursive option in GetPropertyValue. I have added below true.
Below is your code.
Hope it helps to solve your issue.
Cheers,
Shaishav
That's it. That works for me!
Thanks!
is working on a reply...