Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get a specific crop using Umbraco 4.7.1 Razor engine
Given this XML:
<NewsItem id="1140" parentID="1139" level="3" writerID="0" creatorID="0" nodeType="1137" template="1138" sortOrder="1" createDate="2011-08-10T13:46:53" updateDate="2011-08-25T16:51:18" nodeName="Test newsitem" urlName="test-newsitem" writerName="admin" creatorName="admin" path="-1,1051,1139,1140" isDoc="">
<introText><![CDATA[Minime vero, inquit ille, consentit. Quod si ita se habeat, non possit beatam praestare vitam sapientia.]]></introText>
<crops date="25/08/2011 16:08:01">
<crop name="Thumbnail" x="128" y="0" x2="896" y2="768" url="/media/2209/tulips_Thumbnail.jpg" />
<crop name="Sidebar" x="200" y="100" x2="800" y2="500" url="/media/2209/tulips_Sidebar.jpg" />
<pageTitle />
<metaTitle />
<metaKeywords />
<metaDescription />
<navigationTitle />
Just use the following bit of Razor on the page to get the crop named "Thumbnail" (@name is the property named "name"):
<img src="@newsItem.imageCrop.Find("@name", "Thumbnail").url" />

This comment has been minimized.

Copy link

tkahn commented Oct 10, 2011

Thanks for sharing this! The Umbraco forum was cluttered with outdated examples so this was really valuable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.