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?)
OK, if anyone comes across this post, this is how it works for me.
@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='' />
}
Get image url from MacroPartialView
Hi I used to be able to get image url from macro with:
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:
OK, if anyone comes across this post, this is how it works for me.
I think Umbraco.TypedMedia is renamed to just Umbraco.Media. So you can probably do something like.
This will give you a IPublishedContent object, and you can then do:
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.