Here's the Razor example (note the @crops.Find in there), this assumes that your DAMP picker has an alias of "media" and that you store the media XML in your umbraco.config:
<h2>@Model.Name</h2>
<h3>Digibiz Advanced Media Picker</h3>
@{
if (Model.HasValue("Media")) {
dynamic mediaItems = Model.Media.mediaItem;
if (mediaItems.Count() != 0)
{
<ul>
@foreach (var item in mediaItems)
{
var image = item.Image;
<li>
Original image: <a href="@image.umbracoFile">@image.nodeName</a> (@image.umbracoBytes bytes)<br />
@*
If the type of the mediacropper is not XML (but a string) then there
are no crops defined, so I should not try to find the crops.
*@
@{ var crops = image.mediaCropper; }
@if (crops.GetType().ToString() != "System.String")
{
<text>Crops:</text><br />
<img src="@crops.Find("@name", "Thumbnail").url" alt="@image.nodeName"/><br />
<img src="@crops.Find("@name", "Header").url" alt="@image.nodeName"/>
}
</li>
}
</ul>
}
}
}
Get images with a specific cropping ?
Well ... how do I do that ?
It's fairly easy in XSLT but I just can't seem to figure it out in Razor.
Here is my XSLT example:
<xsl:template match="Photos"> <xsl:variable name="images" select="umb:GetMedia(images, 1)" /> <xsl:apply-templates select="$images[Image[cropset/crops/crop[@name='photosMedium']]]" /></ul> </xsl:template> <xsl:template match="Folder"> <ul> <xsl:apply-templates select="Image" /> </ul> </xsl:template> <xsl:template match="Image"> <li> <a href="{umbracoFile}"> <img src="{cropset/crops/crop[@name='photosMedium']/@url}" alt="{@nodeName}" /> </a> </li> </xsl:template>Did you have a look at the Cultiv Razor Examples project? It also has some cropping examples.
Jeroen
Here's the Razor example (note the @crops.Find in there), this assumes that your DAMP picker has an alias of "media" and that you store the media XML in your umbraco.config:
<h2>@Model.Name</h2> <h3>Digibiz Advanced Media Picker</h3> @{ if (Model.HasValue("Media")) { dynamic mediaItems = Model.Media.mediaItem; if (mediaItems.Count() != 0) { <ul> @foreach (var item in mediaItems) { var image = item.Image; <li> Original image: <a href="@image.umbracoFile">@image.nodeName</a> (@image.umbracoBytes bytes)<br /> @* If the type of the mediacropper is not XML (but a string) then there are no crops defined, so I should not try to find the crops. *@ @{ var crops = image.mediaCropper; } @if (crops.GetType().ToString() != "System.String") { <text>Crops:</text><br /> <img src="@crops.Find("@name", "Thumbnail").url" alt="@image.nodeName"/><br /> <img src="@crops.Find("@name", "Header").url" alt="@image.nodeName"/> } </li> } </ul> } } }Don't you need to defend against the crops not existing?
What if Find() returns nothing?
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.