I am integrating my blog into a site style which requires my images to fit in a certain space. Elsewhere I am using Umbraco.TypedMedia and GetCropUrl to achieve this.
My attempt to do something similar on the Master page (or via a macro) looks like this:
var featureImage = Umbraco.TypedMedia(Model.BlogLogo);
var imageUrl = featureImage.GetCropUrl(height: 600, width: 1200, imageCropMode: ImageCropMode.Crop);
This crashes with
Compiler Error Message: CS0234: The type or namespace name 'TypedMedia' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)
The same happens in a macro, if I try it that way.I know that the BlogLogo is from an imagecropper, so there must be a way to make this work, if I can get the references right.
I will try this but I have my doubts. Trouble is that the Articulate plugin (I believe) only gives me the url of the image and not the whole object. I'll report back soon!
Ahh. Now that all sounds good. I have tried the UmbracoHelper. Very useful, thank you. I shall also have a go at the various ways of getting a CropUrl.
I have added an image (articulate crop) to ArticulatePost called Post Image. How would I retrieve that using, say, Model.BlogArchiveNode?
umbracohelper.Field("postImage"); gives me an htmlstring (of a complex src string to put in an img tag). Of course that is not the way to retrieve typed media. But umbracohelper.TypedMedia("postImage") returns null. I tried using the string to return typed media but that gave an exception. I think my solutions are too complicated.
therefore you can do anything with Model that you can do with IPublishedContent and work with it the normal Umbraco way, example:
@(Model.GetPropertyValue<string>("postImage"))
which will return the JSON string stored for the crop. Just like i mentioned above, you can use the GetCropUrl extension method on a string, so you can just do:
I'll try to re-iterate: using TypedMedia = getting media from the media section, it has nothing to do with getting an image or any other property from the current document.
I have used JsonConvert to get at the src part but no further. GetCropUrl just isn't doing the right thing here, in contrast to your own List.cshtml where BlogLogo is directly part of the model.
I've spent all day on this. Starting to think it might work if I use the second override of GetCropUrl: Model.GetCropUrl("postImage", preferFocalPoint=true) and so on.
Model.GetPropertyValue("postImage") returns typeof 'object', and there's no extension method for GetCropUrl on 'object' so seems strange that that is working at all.
works perfectly and does not require any special helper objects or any twisting my code in knots. So many ways to skin a cat but only one is correct. Thanks for your help, I mean it.
glad you got the result you needed! Still not sure why the string extension is not working for you, i haven't had time to try to reproduce your outcome.
Unable to grab BlogLogo as TypedMedia
Hi,
I am integrating my blog into a site style which requires my images to fit in a certain space. Elsewhere I am using Umbraco.TypedMedia and GetCropUrl to achieve this.
My attempt to do something similar on the Master page (or via a macro) looks like this:
var featureImage = Umbraco.TypedMedia(Model.BlogLogo);
var imageUrl = featureImage.GetCropUrl(height: 600, width: 1200, imageCropMode: ImageCropMode.Crop);
This crashes with
Compiler Error Message: CS0234: The type or namespace name 'TypedMedia' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)
The same happens in a macro, if I try it that way.I know that the BlogLogo is from an imagecropper, so there must be a way to make this work, if I can get the references right.
Any ideas?
Hi Amanda,
Did you see that article ?
http://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/
Try like that :
Thanks, Alexander
Thanks Alexander,
I will try this but I have my doubts. Trouble is that the Articulate plugin (I believe) only gives me the url of the image and not the whole object. I'll report back soon!
Amanda
The blog logo isn't a media node, it's just a property on the articulate root node.
TypedMedia = get's a media item in the media tree TypeContent = get's a content item in the content tree
Both return IPublishedContent
The GetCropUrl method is an extension method on IPublishedContent.
The Articulate.Models.IMasterModel contains a property called RootBlogNode which is of type IPublishedContent. Therefore you can use that:
Model.RootBlogNode.GetCropUrl(.... )
one of the values you can pass in to GetCropUrl is the property name, so use the property name for the logo.
Also, GetCropUrl is an extension method on string as well, so you can just do this:
Model.BlogLogo.GetCropUrl(...)
Ahh. Now that all sounds good. I have tried the UmbracoHelper. Very useful, thank you. I shall also have a go at the various ways of getting a CropUrl.
I have added an image (articulate crop) to ArticulatePost called Post Image. How would I retrieve that using, say, Model.BlogArchiveNode?
umbracohelper.Field("postImage"); gives me an htmlstring (of a complex src string to put in an img tag). Of course that is not the way to retrieve typed media. But umbracohelper.TypedMedia("postImage") returns null. I tried using the string to return typed media but that gave an exception. I think my solutions are too complicated.
On a blog post page,
Model
=PostModel
https://github.com/Shazwazza/Articulate/blob/master/Articulate/Models/PostModel.cs
PostModel inherits from:
MasterModel
https://github.com/Shazwazza/Articulate/blob/master/Articulate/Models/MasterModel.cs
which implements the standard
IPublishedContent
therefore you can do anything with
Model
that you can do withIPublishedContent
and work with it the normal Umbraco way, example:which will return the JSON string stored for the crop. Just like i mentioned above, you can use the
GetCropUrl
extension method on a string, so you can just do:I'll try to re-iterate: using TypedMedia = getting media from the media section, it has nothing to do with getting an image or any other property from the current document.
Model.GetPropertyValue("postImage").GetCropUrl(height: 600, width: 1200, imageCropMode: ImageCropMode.Crop);
gets me
"{\r\n \"focalPoint\": {\r\n \"left\": 0.47290640394088668,\r\n \"top\": 0.31666666666666665\r\n },\r\n \"src\": \"/media/1040/beggar.jpg\",\r\n \"crops\": []\r\n}?mode=crop&width=1200&height=600"
Which I cannot use.
I have used JsonConvert to get at the src part but no further. GetCropUrl just isn't doing the right thing here, in contrast to your own List.cshtml where BlogLogo is directly part of the model.
I've spent all day on this. Starting to think it might work if I use the second override of GetCropUrl: Model.GetCropUrl("postImage", preferFocalPoint=true) and so on.
Model.GetPropertyValue("postImage") returns typeof 'object', and there's no extension method for GetCropUrl on 'object' so seems strange that that is working at all.
As noted above, try:
So sorry: I am using that format (I can't have checked my post very well).
Model.GetPropertyValue<string>("postImage").GetCropUrl(...) using height and width parameters retunrs the unchanged Json string .
Please forgive me, especially Shannon.
croppedUrl = Model.GetCropUrl(width:1200, height: 600, propertyAlias:"postImage", cropAlias:null,imageCropMode:ImageCropMode.Crop, preferFocalPoint:true );
works perfectly and does not require any special helper objects or any twisting my code in knots. So many ways to skin a cat but only one is correct. Thanks for your help, I mean it.
glad you got the result you needed! Still not sure why the string extension is not working for you, i haven't had time to try to reproduce your outcome.
is working on a reply...