Skip to content

Instantly share code, notes, and snippets.

Embed
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="">
<categories><![CDATA[allergy]]></categories>
<introText><![CDATA[Minime vero, inquit ille, consentit. Quod si ita se habeat, non possit beatam praestare vitam sapientia.]]></introText>
<bodyText><![CDATA[
<p>Ipsum.</p>
]]></bodyText>
<imageUpload>/media/2209/tulips.jpg</imageUpload>
<imageCrop>
<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" />
</crops>
</imageCrop>
<publishdateOverrule>2011-08-17T00:00:00</publishdateOverrule>
<pageTitle />
<metaTitle />
<metaKeywords />
<metaDescription />
<navigationTitle />
<umbracoNaviHide>0</umbracoNaviHide>
<hideInNavigationForNonLoggedInUsers>0</hideInNavigationForNonLoggedInUsers>
<useDocCheck>0</useDocCheck>
<hideInSitemap>0</hideInSitemap>
<showInTopNavigation>0</showInTopNavigation>
<showInMainMenu>0</showInMainMenu>
<showInFooterMenu>0</showInFooterMenu>
</NewsItem>
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" />
@tkahn

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.