And here's the razor so far, but it just a placeholder for rendering out 1 item so far and i'm using the XmlFunctions.cshtml inside my App_code folder:
I'm only guessing but this is probably because you are passing a DynamicXml object as the first parameter. Try this, no idea whether it will work or not and can't test anything at the moment (you might want to try outputting just Model.galleryArea.galleryImg.mediaItem.Image.thumbPictures.ToXml().ToString()to see what you are getting aswell):
You can probably just navigate through using the DynamicXml, like below, but you will start getting into trouble again when there is more than 1 image selected. Not sure how you would do a selection based on the crop name at the moment either.
I'm new to Razor and I'm interessted in a combination of this topic and the Question for an XML Data Loop topic. So how can I loop through multiple items that are selected with DAMP and then get a specific crop value? Hope someone can give me an example.
I'm testing it out and will share the snippet with you.
My logic behind is for using it for a featured article or a gallery. In the featured article i will have 1 big pictureframe and inside 3 topic related thumbs with pop up.
So i think it's best to check with an if statement if there are multiple media items inside the picker with this loop:
@using umbraco.MacroEngines @foreach(dynamic img in Model.Children) { if(img.imageUpload.ToString() != "") { foreach(dynamic d in img.imageUpload.mediaItem) { if (d.BaseElement.Name == "Image") {<imgsrc="@d.umbracoFile"/>} else {<imgsrc="@d.Image.umbracoFile"/>} } } else {<span>No images selected</span>} }
So the next step of mine is to implement a checkbox for featured article defined in the docType. When checked looping through the crops and add it to the mainpictureframe. i think it sounds a little bit confusing but will show you an example when it's ready to release the snippet.
A logical development could be
If there's checked featured article, look up for the crops inside multiple Items and render it.
Beware! Not every mediaItem has the property Image. Take a look at Dump data type settings. There's a setting that let's you choose if default type for created media is File, Folder or Image (or probably something else if there were more, I can't tell). The default is File. This was the reason why my code worked for the first image (from library) and crashed on the second one - created by DUMP. There are probably more catches like these. This is precisely why I hate dynamic keyword in C#!
Trying DAMP and Image Cropper datatypes for the first time. Using razor and using CultivRazorExamples and forum posts as a guide I can't get hold of a crop that I know is there. It's a 4.7.2 site.
The Macro is:-
@{
var pagesToList = @Model.Children.Where("Visible");
var width = Parameter.w;
var height = Parameter.h;
foreach (var newsItem in pagesToList) {
var newsCopy = newsItem.bodyText;
newsCopy = Library.StripHtml(newsCopy);
newsCopy = Library.Truncate(newsCopy, 200, true);
var newsImage = ""; //newsItem.image1.mediaItem.Image.imageCropper.crops.crop.Find("name","News Item").url;
foreach (dynamic crop in newsItem.image1.mediaItem.Image.imageCropper.crops)
{
if(crop.name == "News Item")
{
newsImage = crop.url;
}
}
<article class="newsListItem">
<a href="@newsItem.Url"><img src="/ImageGen.ashx?image=@newsImage&AltImage=noimage-newslist.gif&width=@width&height=@height" width="@width" height="@height" alt="@newsItem.summaryHeadline"></a>
<h3><a href="@newsItem.Url">@newsItem.headline</a></h3>
<p>@newsCopy</p>
</article>
}
}
The XML from umbraco.config is:-
<NewsItemPage id="1098" parentID="1097" level="3" writerID="0" creatorID="0" nodeType="1095" template="1096" sortOrder="1" createDate="2012-06-04T23:11:04" updateDate="2012-06-18T14:51:41" nodeName="NewsItem1" urlName="newsitem1" writerName="admin" creatorName="admin" path="-1,1053,1097,1098" isDoc="">
<headline><![CDATA[This is the first articles headline]]></headline>
<bodyText><![CDATA[
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris
varius eros eu nulla convallis adipiscing. Sed ultrices mollis dui
sit amet consectetur. Pellentesque interdum ante at risus sodales
</p>
]]></bodyText>
<articleExcerpt><![CDATA[Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eget arcu in elit euismod facilisis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In nec purus ultricies risus suscipit porta sit amet non nunc.]]></articleExcerpt>
<newsListImage><![CDATA[]]></newsListImage>
<image1>
<DAMP fullMedia="">
<mediaItem>
<Image id="1217" version="8a511a02-07d1-42e1-bb87-490da6ba9174" parentID="1119" level="2" writerID="0" nodeType="1032" template="0" sortOrder="1" createDate="2012-06-10T21:45:43" updateDate="2012-06-10T21:45:43" nodeName="Holly In Wnter" urlName="hollyinwnter" writerName="admin" nodeTypeAlias="Image" path="-1,1119,1217">
<umbracoFile>/media/2376/Holly in wnter.jpg</umbracoFile>
<umbracoWidth>2248</umbracoWidth>
<umbracoHeight>1360</umbracoHeight>
<umbracoBytes>444434</umbracoBytes>
<umbracoExtension>jpg</umbracoExtension>
<imageCropper>
<crops date="2012-06-10T21:45:43">
<crop name="Home Thumbnails" x="149" y="452" x2="1557" y2="1360" url="/media/2376/Holly in wnter_Home Thumbnails.jpg" />
<crop name="Submenu Thumbnails" x="580" y="0" x2="1668" y2="1360" url="/media/2376/Holly in wnter_Submenu Thumbnails.jpg" />
<crop name="News Item" x="215" y="2" x2="1573" y2="1360" url="/media/2376/Holly in wnter_News Item.jpg" />
<crop name="Contact Page" x="0" y="118" x2="2248" y2="1242" url="/media/2376/Holly in wnter_Contact Page.jpg" />
<crop name="Gallery Image" x="444" y="0" x2="1804" y2="1360" url="/media/2376/Holly in wnter_Gallery Image.jpg" />
<crop name="Zoomable Image" x="0" y="155" x2="2248" y2="1204" url="/media/2376/Holly in wnter_Zoomable Image.jpg" />
</crops>
</imageCropper>
</Image>
</mediaItem>
</DAMP>
</image1>
<image2>
<DAMP fullMedia="">
<mediaItem>
<Image id="1218" version="af108270-aaaf-4c97-8a67-38ee518ddad7" parentID="1119" level="2" writerID="0" nodeType="1032" template="0" sortOrder="2" createDate="2012-06-10T21:45:43" updateDate="2012-06-10T21:45:43" nodeName="Loch Clair" urlName="lochclair" writerName="admin" nodeTypeAlias="Image" path="-1,1119,1218">
<umbracoFile>/media/2381/Loch Clair.JPG</umbracoFile>
<umbracoWidth>3456</umbracoWidth>
<umbracoHeight>2304</umbracoHeight>
<umbracoBytes>1561867</umbracoBytes>
<umbracoExtension>JPG</umbracoExtension>
<imageCropper>
<crops date="2012-06-10T21:45:43">
<crop name="Home Thumbnails" x="827" y="188" x2="2770" y2="1441" url="/media/2381/Loch Clair_Home Thumbnails.jpg" />
<crop name="Submenu Thumbnails" x="806" y="0" x2="2649" y2="2304" url="/media/2381/Loch Clair_Submenu Thumbnails.jpg" />
<crop name="News Item" x="576" y="0" x2="2880" y2="2304" url="/media/2381/Loch Clair_News Item.jpg" />
<crop name="Contact Page" x="0" y="288" x2="3456" y2="2016" url="/media/2381/Loch Clair_Contact Page.jpg" />
<crop name="Gallery Image" x="576" y="0" x2="2880" y2="2304" url="/media/2381/Loch Clair_Gallery Image.jpg" />
<crop name="Zoomable Image" x="0" y="345" x2="3456" y2="1957" url="/media/2381/Loch Clair_Zoomable Image.jpg" />
</crops>
</imageCropper>
</Image>
</mediaItem>
</DAMP>
</image2>
<backgroundImage>1086</backgroundImage>
<pageTitle>News Item</pageTitle>
<metaDescription />
<metaKeywords />
<hideSubNav>0</hideSubNav>
<xmldumpAllowed>0</xmldumpAllowed>
<umbracoNaviHide>0</umbracoNaviHide>
<hideFromSearchAndSitemap>0</hideFromSearchAndSitemap>
</NewsItemPage>
NewsItemPage are children of NewsAreaPage. Each NewsItemPage has two images, I just want to show the first image.
The umbDebugShowTrace gives: "Error Loading Razor Script (file: Get News Items List) 'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'name'", yet it is there. Other iterations of this code (from the cultivRazorExamples insisted that url wasn't there as well. There must be some syntax problem somewhere but I'm too new to see it.
DAMP concerned retrieving Crop url @ Sebastiaan
Okay let's start. The past 2 days we've managed to return multiple Images via Damp and Razor.
Now next step. I've added to the MediaType an imageCropper with 2 values and want to retrieve the url data to output it for a galleryListing.
Here's the XML:
And here's the razor so far, but it just a placeholder for rendering out 1 item so far and i'm using the XmlFunctions.cshtml inside my App_code folder:
And it give's back this error:
error CS1501: No overload for method 'GetAttributeValue' takes 1 arguments
Any ideas solving this problem?
dear sincerely Toni
Not used XmlFunctions, but I would guess from the error message that you have got an extra closing bracket in there. Try this:
<img src="@XmlFunctions.GetAttributeValue(Model.galleryArea.galleryImg.mediaItem.Image.thumbPictures, "/crops/crop[@name = 'thumbSmall']", "url")" alt=""/>
Throws an error while rendering out:
The best overloaded method match for 'ASP.XmlFunctions.GetAttributeValue(string, string, string)' has some invalid arguments
I'm only guessing but this is probably because you are passing a DynamicXml object as the first parameter. Try this, no idea whether it will work or not and can't test anything at the moment (you might want to try outputting just Model.galleryArea.galleryImg.mediaItem.Image.thumbPictures.ToXml().ToString()to see what you are getting aswell):
<img src="@XmlFunctions.GetAttributeValue(Model.galleryArea.galleryImg.mediaItem.Image.thumbPictures.ToXml().ToString(), "/crops/crop[@name = 'thumbSmall']", "url")" alt=""/>
Okay not giving back an error but it's not rendering the image hmpf.
are there any other possibilities to retrieve the data inside the crops (url)?
You can probably just navigate through using the DynamicXml, like below, but you will start getting into trouble again when there is more than 1 image selected. Not sure how you would do a selection based on the crop name at the moment either.
@Model.galleryArea.galleryImg.mediaItem.Image.thumbPictures.crops.crop[0].url
Maybe do something like this
edited because I was using our earlier example structure from the other thread
okay solved. :) thanks for the help alex. Couldn't realize that it's so easy to target the value inside the crop with the . notation.
My oppinion razor rocks alot more than xslt does :)
Hello,
I'm new to Razor and I'm interessted in a combination of this topic and the Question for an XML Data Loop topic. So how can I loop through multiple items that are selected with DAMP and then get a specific crop value? Hope someone can give me an example.
Jeroen
I'm testing it out and will share the snippet with you.
My logic behind is for using it for a featured article or a gallery. In the featured article i will have 1 big pictureframe and inside 3 topic related thumbs with pop up.
So i think it's best to check with an if statement if there are multiple media items inside the picker with this loop:
So the next step of mine is to implement a checkbox for featured article defined in the docType.
When checked looping through the crops and add it to the mainpictureframe. i think it sounds a little bit confusing but will show you an example when it's ready to release the snippet.
A logical development could be
If there's checked featured article, look up for the crops inside multiple Items and render it.
Stay tuned :)
A good example for using DUMP in Razor is in Cultiv Razor Examples.
@foreach (var item in mediaItems)
{
var image = item.Image;
}
Beware! Not every mediaItem has the property Image. Take a look at Dump data type settings. There's a setting that let's you choose if default type for created media is File, Folder or Image (or probably something else if there were more, I can't tell). The default is File. This was the reason why my code worked for the first image (from library) and crashed on the second one - created by DUMP. There are probably more catches like these. This is precisely why I hate dynamic keyword in C#!
Hi,
Trying DAMP and Image Cropper datatypes for the first time. Using razor and using CultivRazorExamples and forum posts as a guide I can't get hold of a crop that I know is there. It's a 4.7.2 site.
The Macro is:-
The XML from umbraco.config is:-
NewsItemPage are children of NewsAreaPage. Each NewsItemPage has two images, I just want to show the first image.
The umbDebugShowTrace gives: "Error Loading Razor Script (file: Get News Items List) 'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'name'", yet it is there. Other iterations of this code (from the cultivRazorExamples insisted that url wasn't there as well. There must be some syntax problem somewhere but I'm too new to see it.
Any help would be greatly appreciated.
Craig
Hello,
I've released the DAMP Razor Model package. It's now much easier to use DAMP in Razor. It also has some examples and you can see a demo here: http://www.screenr.com/qvj8.
Jeroen
is working on a reply...