먼저, 렌더링 아이템의 미디어 정보를 가져오는 중, 아주 유용한 정보를 찾았다. 아래는 Muhammad Jameel 블로그에서 가져온것이다.
Create an object for the target item in the database- replace itempath with the relative path to the item in the Content Tree, such as “home/about/item1” or start the path with a backslash (/) to indicate an absolute path, such as “/sitecore/content/home/about/item1”– a null value will be set in either case if the item does not exist - Sitecore does compare case when evaluating item paths.
1 2 3 4 5 6 7 8 9 10 11 12 | Sitecore.Data.Database db = Sitecore.Context.Database; Sitecore.Data.Items.Item item = db.GetItem("itempath"); Sitecore.Data.Fields.ImageField image = item.Fields["imagefield"]; if (image!=null && image.MediaItem!=null) { Sitecore.Data.Items.MediaItem image = new Sitecore.Data.Items.MediaItem(imageField.MediaItem); string src = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(image)); if (!string.IsNullOrEmpty(src)) { string imgTag = String.Format(@"<img src=""{0}"" alt=""{1}"" />", src, image.Alt); } } |