Hi folks, esp. Jeavon, need some help with the image cropper, esp.
the responsive version if possible, but just getting a crop to work
would be nice.
So originally I could get my images to display but they were not cropped. My code was;
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{ Layout = "tmpContentPage.cshtml";
var homePage = CurrentPage.AncestorsOrSelf(1).First(); var ourMachines = homePage.dtOurMachines.First(); var machineItems = ourMachines.dtOurMachineDetails.Take(5); }
I
also tried the variation of: "GetCropUrl(propertyAlias:
"propMachinePhoto", height:150, width:250)" but no luck, the image would
appear but it wasn't cropped. This led me to this topic.
So I proceeded to update the ImageProcessor - which it looked likes it needed - but it broke all my images as noted in this topic.
I managed to get the image back afterwards with this...
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{ Layout = "tmpContentPage.cshtml";
var homePage = CurrentPage.AncestorsOrSelf(1).First(); var ourMachines = homePage.dtOurMachines.First(); var machineItems = ourMachines.dtOurMachineDetails.Take(5); }
'Newtonsoft.Json.Linq.JObject' does not contain a definition for 'GetCropUrl'
Now I get that, because
@machine.propMachinePhoto
now returns a JSON object. What I don't get is why this command
before I updated ImageProcessor did not trigger this error, instead it
displayed the JSON in the image URL. Obviously not correct but it was
different.
var homePage = CurrentPage.AncestorsOrSelf(1).First(); var ourMachines = homePage.dtOurMachines.First(); var machineItems = ourMachines.dtOurMachineDetails.Take(5);
Thank you for changing the code to quit, this makes a lot of sense, thank you :)
Unfortunately when I updated my Partial View appropriately to suit, I got this error;
Exception Details: System.InvalidOperationException: Sequence contains no elements
Line 15: // Then take the first one, as we know there will only be on news overview page
Line 16: //var ourMachines = homePage.dtOurMachines.First();
Line 17: var ourMachines = homePage.Children.OfTypes("dtOurMachine").First(); Line 18:
Line 19:
I am assuming that there is something either;
a) wrong with my Data Type structure (although the runtime version of this code works fine with the current structure)
b) this is related to the ImageProcessor issue I'm experiencing.
BTW: I've checked out the ImageProcessor site and all of the entries in the various configuration files seem to be setup correctly. The references appear to be setup properly in my project. This is weird! :P
I took a guess that you were using the dynamic pluraliser when I converted this but perhaps not, should the document type alias be "dtOurMachines" or "dtOurMachine"?
Nah for some reason in the context I am cosing in the Pluraliser is not needed. This is the kind fo rstuff that is confusing me haha
So the document types are "dtOurMachines" and "dtOurMachineDetails".
Unfortunately I get a "The value of parameter 'id' must be either a string or an integer" error on "var machinePhoto = Umbraco.TypedMedia(machine.GetPropertyValue("propMachinePhoto"));"
Totally agree, dynamics is complicated especially stuff like pluralisation.
A bit strange, TypedMedia should accept a object, perhaps try Umbraco.TypedMedia(machine.GetPropertyValue<int>
("propMachinePhoto"));" instead and see if you get anywhere
Yay! It's not a media item, it's a image Cropper directly on your content node to you don't need a media item at all. You can use a cropper on both content and media, just depends on your structure (generally media is used for reuse).
I know your up against it, but if you can find a hour, watch this video https://www.youtube.com/watch?v=bQsvGmnYaUU I walk through using the cropper on content and then also using it on media.
Unfortunately I'm in a position where I have a project that demanded a CMS, I have not used MVC before, and know only a little C# (VB guy here). So I am learning 3 things at once, with what I find to be poor or confusing documentation, and a short time frame.
Not a good situation to be in but in this instance unavoidable.
I will definitely watch the video ASAP. If I can resolve my other problem I need to get the rest of this site implemented to present to client then I'll come back to it. Unless I break it again of course, then I will HAVE to watch it sooner :P
Actually talking documentation, what do you find to be the most useful sources of actual reference for Umbraco, like APIs, Classes, Methods, and how things work together etc.?
Getting a Responsive Image Cropper to work
Hi folks, esp. Jeavon, need some help with the image cropper, esp. the responsive version if possible, but just getting a crop to work would be nice.
So originally I could get my images to display but they were not cropped. My code was;
I also tried the variation of: "GetCropUrl(propertyAlias: "propMachinePhoto", height:150, width:250)" but no luck, the image would appear but it wasn't cropped. This led me to this topic.
So I proceeded to update the ImageProcessor - which it looked likes it needed - but it broke all my images as noted in this topic.
I managed to get the image back afterwards with this...
but now this version;
Ends up with the error:
'Newtonsoft.Json.Linq.JObject' does not contain a definition for 'GetCropUrl'
Now I get that, because
now returns a JSON object. What I don't get is why this command before I updated ImageProcessor did not trigger this error, instead it displayed the JSON in the image URL. Obviously not correct but it was different.
So my question is... how do I get this;
into something like this;
Where I don't get an error, I do get an image, and it's cropped?
Lastly... I was unable to use your example Jeavon;
Without changing it to get...
... using an example from the same Starter Kit... where I used the var declarations at the top to get this part of your example to kind of work;
My questions;
- How did you get the objects "homePage" and "umbTextPages" in your example?
- How can you write a version of your example in such a way that one can get intellisense in Visual Studio?
Hope the above made sense. I'm really tired at 1:30am. Time to sleep.
Thanks.
Ok, I do talk about using width and height in uHangOut EP30 (around 18 minutes) and the need to strongly type the media item.
Anyhow from what I have gathered, below is a strongly typed version (for intellisense):
So for full intellisense, always use
Model.Content
,TypedContent
andTypedMedia
Jeavon
Hi Jeavon,
Thank you for changing the code to quit, this makes a lot of sense, thank you :)
Unfortunately when I updated my Partial View appropriately to suit, I got this error;
Exception Details: System.InvalidOperationException: Sequence contains no elements
Line 15: // Then take the first one, as we know there will only be on news overview page Line 16: //var ourMachines = homePage.dtOurMachines.First(); Line 17: var ourMachines = homePage.Children.OfTypes("dtOurMachine").First(); Line 18: Line 19:
I am assuming that there is something either;
a) wrong with my Data Type structure (although the runtime version of this code works fine with the current structure)
b) this is related to the ImageProcessor issue I'm experiencing.
BTW: I've checked out the ImageProcessor site and all of the entries in the various configuration files seem to be setup correctly. The references appear to be setup properly in my project. This is weird! :P
Cheers,
Jeremy
I took a guess that you were using the dynamic pluraliser when I converted this but perhaps not, should the document type alias be "dtOurMachines" or "dtOurMachine"?
Nah for some reason in the context I am cosing in the Pluraliser is not needed. This is the kind fo rstuff that is confusing me haha
So the document types are "dtOurMachines" and "dtOurMachineDetails".
Unfortunately I get a "The value of parameter 'id' must be either a string or an integer" error on "var machinePhoto = Umbraco.TypedMedia(machine.GetPropertyValue("propMachinePhoto"));"
I'm thinking I can figure this one out though.
Totally agree, dynamics is complicated especially stuff like pluralisation.
A bit strange, TypedMedia should accept a object, perhaps try
Umbraco.TypedMedia(machine.GetPropertyValue<int> ("propMachinePhoto"));"
instead and see if you get anywhereCan I just double check is propMachinePhoto a media picker or is it a cropper?
Hmmm it's a Cropper
Ok, change it to this then:
Yeah baby!! That was it... ZOMG :)
Does that mean that "machine" was a Media item already?, thus creating a machinePhoto was unnecessary.
Yay! It's not a media item, it's a image Cropper directly on your content node to you don't need a media item at all. You can use a cropper on both content and media, just depends on your structure (generally media is used for reuse).
I know your up against it, but if you can find a hour, watch this video https://www.youtube.com/watch?v=bQsvGmnYaUU I walk through using the cropper on content and then also using it on media.
Thanks Jeavon, your help has been invaluable.
Unfortunately I'm in a position where I have a project that demanded a CMS, I have not used MVC before, and know only a little C# (VB guy here). So I am learning 3 things at once, with what I find to be poor or confusing documentation, and a short time frame.
Not a good situation to be in but in this instance unavoidable.
I will definitely watch the video ASAP. If I can resolve my other problem I need to get the rest of this site implemented to present to client then I'll come back to it. Unless I break it again of course, then I will HAVE to watch it sooner :P
Actually talking documentation, what do you find to be the most useful sources of actual reference for Umbraco, like APIs, Classes, Methods, and how things work together etc.?
You're very welcome!
For documentation always check here first
Probably my most used sections are:
is working on a reply...