Using MS visual studio 2012, c# 4.5 and Umbraco 7.1.
I have been tweaking my master page, and i noticed i had to make images recursive (display on every page).
with property's its no problem, you simply say for example:
@Umbraco.Field("pageTitle", recursive:true)
this works fine, however for images its a little different as im using a media picker as the datatype for the image, when you do this you need to add some extra code like the following
this display the image correctly which is great, but as it does not use umbraco.field i cant see how to use "recursive". I've tried looking at some old documentation but doesn't really reference images. And as most will know the new info Isn't quiet available + from what i found there was no mention of recursive images.
The way you can make a property recursive in Umbraco is by adding a underscore in the front of your ._propertyAlias. Some something like this will make it recursive.
I am sorry. Putting an underscore in front of the alias is not making the result of the Image Picker recursive. Umbraco can't find the image then. "myImage" is ok but "_myImage" is not working.
Yes it works but with a twist. I need to put "true" in 2 places. One like you suggest and another at the other place where "mainImage" is mentioned. This is the code that works for me. Please notice the places with TRUE.
Recursive Image from media picker
Using MS visual studio 2012, c# 4.5 and Umbraco 7.1.
I have been tweaking my master page, and i noticed i had to make images recursive (display on every page).
with property's its no problem, you simply say for example:
this works fine, however for images its a little different as im using a media picker as the datatype for the image, when you do this you need to add some extra code like the following
this display the image correctly which is great, but as it does not use umbraco.field i cant see how to use "recursive". I've tried looking at some old documentation but doesn't really reference images. And as most will know the new info Isn't quiet available + from what i found there was no mention of recursive images.
Is this possible? Am i missing something?
cheers guys
Hi Steven,
The way you can make a property recursive in Umbraco is by adding a underscore in the front of your ._propertyAlias. Some something like this will make it recursive.
You could try something like this:
Maybe you don't need the if statement since you go recursively up through the content tree, until you find an image.
If you are new to razor there a some good resources I think could be nice to know. e.g the cheatsheets
http://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets
If you´re using Umbraco 7, you can still use the cheatsheets, as far as I know there isen´t the big difference in Umbraco 6 and 7 razor, if any.
http://our.umbraco.org/documentation/Reference/Templating/Mvc/
Hope this helps,
/Dennis
Hi Dennis
I am sorry. Putting an underscore in front of the alias is not making the result of the Image Picker recursive. Umbraco can't find the image then. "myImage" is ok but "_myImage" is not working.
Am I missing a setting or??
//Lars
Hi Lars,
What if you do something like this would it work for you?.
/Dennis
Hi Dennis
Thank you for your answer.
Yes it works but with a twist. I need to put "true" in 2 places. One like you suggest and another at the other place where "mainImage" is mentioned. This is the code that works for me. Please notice the places with TRUE.
// Lars
Hi Dennis/Lars,
Thanks for your help recursive image worked for me. But my code is bit different from yours. May be this below code mite help some person.
if (Model.Content.HasValue("Image", true))
{
var mediaItem = Umbraco.TypedMedia(Model.Content.GetPropertyValue("Image", true));
<img src="@mediaItem.GetPropertyValue("umbracoFile")" />
}
Thanks
You're welcome :-)
is working on a reply...