Reputation: 860
Hi I used to be able to get image url from macro with:
var imgMain = Model.MacroParameters["image"];
int imgWidth = Convert.ToInt32(Model.MacroParameters["imageWidth"]);
var mediaItemOne = Umbraco.TypedMedia(imgMain);
<img src='@mediaItemOne.Url.GetCropUrl(width:imageWidth)' alt=''/ >
What is the new way in Umbraco 8 as I get the following error now and I cannot find any documentation on how to do it:
UmbracoHelper' does not contain a definition for 'TypedMedia' and no accessible extension method 'TypedMedia' accepting a first argument of type 'UmbracoHelper' could be found (are you missing a using directive or an assembly reference?)
Upvotes: 1
Views: 1951
Reputation: 102
Try this
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@{
var site = Model.Root();
var bannerImage = Model.Value<IPublishedContent>("bannerImage");
}
<img scr="@bannerImage.Url" />
Upvotes: 0
Reputation: 2316
Instead of Umbraco.TypedMedia
, just use Umbraco.Media
the APIs have been simplified as dynamics are no longer supported and the former method is no longer necessary.
The same goes for Content - TypedContent
has gone away, and now Umbraco.Content
returns a strongly typed IPublishedContent item.
Upvotes: 2
Reputation: 860
OK, if anyone comes across this post, this is how I finally got it to work in Umbraco 8
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using Umbraco.Web;
@using Umbraco.Web.Composing
@{
var img = Model.MacroParameters["image"].ToString();
int imageWidth = Convert.ToInt32(Model.MacroParameters["imageWidth"]);
var udi = Udi.Parse(img);
var imgUrl = Current.UmbracoHelper.ContentQuery.Media(udi).Url;
<img src='@imgUrl.GetCropUrl(width:imageWidth)' alt='' />
}
Upvotes: 1