I've never had this before and can't work out why it's happeneing..
I have a standard setup wheremy template uses the @inherits Umbraco.Web.Mvc.UmbracoTemplatePage.
I then have a seies of @sections throughout the page to drop in bits I need. Everything displays fine. What I would like to do is use a media picker to pull in an image from the media section. I have done this on another site easily enough, so thought I'll just recycle the code (below).
Have you tried something like this. This should give you the picture from the media picker with an alias of frontImage, if the currentpage has any picture asigned.
@if (CurrentPage.HasValue("frontImage")){ var dynamicMediaItem = Umbraco.Media(CurrentPage.frontImage); <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/> }
I didn't realise it had been depreciated. I guess that's the problem running a few instances of Umbraco - I need to keep a log of what is transferable and what is not (some are on 6, some on 7)
Display an image
I've never had this before and can't work out why it's happeneing..
I have a standard setup wheremy template uses the @inherits Umbraco.Web.Mvc.UmbracoTemplatePage.
I then have a seies of @sections throughout the page to drop in bits I need. Everything displays fine. What I would like to do is use a media picker to pull in an image from the media section. I have done this on another site easily enough, so thought I'll just recycle the code (below).
For some reason this then breaks my page. The image pulls through fine, but the rest of the page show the razor code instead of rendering the items.
This is how it's rendering on the page in plain text.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ Layout = "Main.cshtml"; } @section Head { } @section Main {
@Umbraco.Field("textArea")
So to clarify, when I add in a macro, the template seems to ignore the fact it should be inheriting a master page from above using:
And instead renders the macro and takes everything else as literal text..
Hi Tom,
Have you tried something like this. This should give you the picture from the media picker with an alias of frontImage, if the currentpage has any picture asigned.
@if (CurrentPage.HasValue("frontImage")){
var dynamicMediaItem = Umbraco.Media(CurrentPage.frontImage);
<img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/>
}
You can find the documentation for the media picker here: https://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Media-Picker If you are using Umbraco 7, then only look that the MVC View Example dynamic and strongly typed. The Razor Macro (DynamicNode & DynamicMedia) Example is old razor syntax which is deprecated.
Hope this helps,
/Dennis
Perfect!
I didn't realise it had been depreciated. I guess that's the problem running a few instances of Umbraco - I need to keep a log of what is transferable and what is not (some are on 6, some on 7)
Thanks a lot for the quick response.
Hi Tom,
In addition to my post above, try to see my comment in this post https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/59874-Razor-in-U7Am-I-just-over-tired?p=0#comment202799 about the different between the old DynamicNode razor that you have been used in Umbraco 6, and the MVC that is used in Umbraco 7.
/Dennis
is working on a reply...