I assume that you are talking about that you want the background image on the body tag.
If so the you can do it like this.
@{ var mediaItem = Umbraco.TypedMedia(Model.Content.GetPropertyValue("bodyBackgroundImage")); } <body style="background:url('@mediaItem.Url');">
or by using this:
@{ var mediaItem = Umbraco.TypedMedia(Model.Content.GetPropertyValue("bodyBackgroundImage")); } <body style="background:url('@mediaItem.GetPropertyValue("umbracoFile")');">
With this code you will get the background image there is set for the page that you are viewing in the browser. If you want to have one place you set the background image for the hole site e.g on the home item, you need to use the AnscestorOfSelf axis you can read about the axis here: http://our.umbraco.org/documentation/reference/templating/macros/razor/using-razor-axes be ware that these foreach loop they are showing are using the old DynamicNode Razor.
Another good resource is the Razor cheat sheets http://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets, I know that it´s says that it for Umbraco 6. But you can also use it for Umbraco 7, and there are all version of Razor for Umbraco. The old DynamicNode but you should not use this if you are using Umbraco 7. And there are cheat sheets for the Dynamic razor and the strongly typed razor.
@Umbraco Issues accessing Media
Hi Guys,
I'm having issues trying to access Media within the @Umbraco model.
This line of code returns me nothing but an empty src string - any ideas why?? I do have images within media, do I need to specify the folder as well?
Hi Jordy,
Do you have a media picker within your CurrentPage?
This is how you get the media item from the picker:
Here the media picker property alias is "mainImage"
Does this help you?
Jeavon
Hi Jordy,
I assume that you are talking about that you want the background image on the body tag.
If so the you can do it like this.
or by using this:
With this code you will get the background image there is set for the page that you are viewing in the browser. If you want to have one place you set the background image for the hole site e.g on the home item, you need to use the AnscestorOfSelf axis you can read about the axis here: http://our.umbraco.org/documentation/reference/templating/macros/razor/using-razor-axes be ware that these foreach loop they are showing are using the old DynamicNode Razor.
Another good resource is the Razor cheat sheets http://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets, I know that it´s says that it for Umbraco 6. But you can also use it for Umbraco 7, and there are all version of Razor for Umbraco. The old DynamicNode but you should not use this if you are using Umbraco 7. And there are cheat sheets for the Dynamic razor and the strongly typed razor.
Hope this helps,
/Dennis
DENNIS YOU BEAUTY!! Thank you so much - I used your second option.
is working on a reply...