Created
August 25, 2011 14:54
-
-
Save nul800sebastiaan/1170848 to your computer and use it in GitHub Desktop.
Get a specific crop using Umbraco 4.7.1 Razor engine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing this! The Umbraco forum was cluttered with outdated examples so this was really valuable.