For some reason the DAMP_Item's Crops and TypedCrops properties throws a nullreference exception, even though the crops are in the XML. Here's a sample of the XML.
And here's a sample of the razor code being used, and also the error message.
foreach(var d in Model.articleImage) { <h1>@d.Crops.test.url</h1> }
Error Loading Razor Script (file: Article With Image Content) Object reference not set to an instance of an object. at DAMP.RazorModel.DAMP_Item.get_Crops() at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at ASP._Page_macroScripts_ArticleWithImageContent_cshtml.Execute() in c:\Work\Mercurial Repos\Louis Poulsen\Umbraco\Umbraco.Site\MacroScripts\ArticleWithImageContent.cshtml:line 7 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) at System.Web.WebPages.WebPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage) at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
Here's the object as seen through visual studio.
Running umbraco 4.11.1, DAMP 2.0, DAMP Razor Model 1.2
I already see the problem, but you couldn't know that ;-). When I fetch the crops I do this with an Xpath and I search for the first element named "crop" I find. Normally it would find this piece of xml:
But you named your Image Cropper property on the Media Type also crop so now this is the xml it will find:
<crop>
Just rename the alias of the Image Cropper datatype to something other than "crop" and it should be fixed just like I said here ;-). After you've done this you'll need to resave the media items because otherwise the xml is not updated. After that it should work :-).
I'm having a similar problem (I think) with umb 6.0.2 and a Razor macro.
I have a page with a DAMP that has 3 images in it. I've used Jeroen's method of creating a special Media Type and Crop Data Type and DAMP Data Type for it. I can upload images as the correct Media Type and I can set and save the crop in the UI preview. All very nice.
In the XML tree I can see the images saved as shown below. The DAMP media picker is called "sideImages":-
<root id="-1"> <Home id="1057" parentID="-1" level="1" creatorID="0" sortOrder="0" createDate="2013-03-08T19:39:48" updateDate="2013-03-10T14:55:27" nodeName="Home" urlName="home" path="-1,1057" isDoc="" nodeType="1055" creatorName="admin" writerName="admin" writerID="0" template="1054"> <sideImages>1125,1127,1128</sideImages> <imageCredits><![CDATA["The Fat Lady Sings in Little Grimley" and "Round the Horne - Back Again!" performed in April 2012]]></imageCredits> <includeInMainNav>1</includeInMainNav> <includeInFooterNav>0</includeInFooterNav> <keywords /> <pageTitle><![CDATA[]]></pageTitle> <description><![CDATA[]]></description>
In the macro to display the three images I've tried:-
@inherits umbraco.MacroEngines.DynamicNodeContext @{ DAMP.PropertyEditorValueConverter.Model mediaItems = new DAMP.PropertyEditorValueConverter.Model(Model.GetPropertyValue("sideImages")); foreach(dynamic item in mediaItems) { <img src="@item.File" alt="@item.Alt"> } }
This displays the files at full size, not the crops. So I've tried <img src="@item.Crops["crop"]" alt="@item.Alt"> and <img src="@item.TypedCrops["Right Hand Image"]" alt="@item.Alt"> but both break the macro when run. These are the values in the DAMP Data Type being used in the "Dsiplay Options" for the Image Cropper Property Alias and Crop Name.
Thanks Jeroen. I agree with Nick's comments on the "Nothing seems to work" post. I installed the DAMP Property Editor Value Convertor in error as well.
Thanks for the DAMP Gallery pointer, I'll take a look at it now.
Problem getting crops using RazorModel
For some reason the DAMP_Item's Crops and TypedCrops properties throws a nullreference exception, even though the crops are in the XML. Here's a sample of the XML.
And here's a sample of the razor code being used, and also the error message.
Here's the object as seen through visual studio.
Running umbraco 4.11.1, DAMP 2.0, DAMP Razor Model 1.2
Welp, forgot the image. Editing your post apparently doesn't work.
http://imgur.com/9j3ZduV
Hello,
I already see the problem, but you couldn't know that ;-). When I fetch the crops I do this with an Xpath and I search for the first element named "crop" I find. Normally it would find this piece of xml:
But you named your Image Cropper property on the Media Type also crop so now this is the xml it will find:
Just rename the alias of the Image Cropper datatype to something other than "crop" and it should be fixed just like I said here ;-). After you've done this you'll need to resave the media items because otherwise the xml is not updated. After that it should work :-).
Jeroen
I'm having a similar problem (I think) with umb 6.0.2 and a Razor macro.
I have a page with a DAMP that has 3 images in it. I've used Jeroen's method of creating a special Media Type and Crop Data Type and DAMP Data Type for it. I can upload images as the correct Media Type and I can set and save the crop in the UI preview. All very nice.
In the XML tree I can see the images saved as shown below. The DAMP media picker is called "sideImages":-
<root id="-1">
<Home id="1057" parentID="-1" level="1" creatorID="0" sortOrder="0" createDate="2013-03-08T19:39:48" updateDate="2013-03-10T14:55:27" nodeName="Home" urlName="home" path="-1,1057" isDoc="" nodeType="1055" creatorName="admin" writerName="admin" writerID="0" template="1054">
<sideImages>1125,1127,1128</sideImages>
<imageCredits><![CDATA["The Fat Lady Sings in
Little Grimley" and
"Round the Horne - Back Again!"
performed in April 2012]]></imageCredits>
<includeInMainNav>1</includeInMainNav>
<includeInFooterNav>0</includeInFooterNav>
<keywords />
<pageTitle><![CDATA[]]></pageTitle>
<description><![CDATA[]]></description>
In the macro to display the three images I've tried:-
This displays the files at full size, not the crops. So I've tried <img src="@item.Crops["crop"]" alt="@item.Alt"> and <img src="@item.TypedCrops["Right Hand Image"]" alt="@item.Alt"> but both break the macro when run. These are the values in the DAMP Data Type being used in the "Dsiplay Options" for the Image Cropper Property Alias and Crop Name.
How do I get the crop?
Craig
You're storing the values as id's so I can't see how the media xml looks like.
It also looks like you're using the DAMP Property Editor Value Converter in a Razor macro instead of MVC. More info about that here: http://our.umbraco.org/projects/backoffice-extensions/digibiz-advanced-media-picker/digibiz-advanced-media-picker/38888-Nothing-Seems-to-Work!#comment141954
You could try the DAMP gallery for a good example.
Jeroen
Thanks Jeroen. I agree with Nick's comments on the "Nothing seems to work" post. I installed the DAMP Property Editor Value Convertor in error as well.
Thanks for the DAMP Gallery pointer, I'll take a look at it now.
Craig
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.