Umbaco Archtype rendering images (MediaPicker2)

余生颓废 提交于 2019-12-02 03:31:54

I just went on a roller-coaster figuring this out!

You can get an IPublishedContent from your image string using this code:

// Your string which is retrieved from Archetype.
var imageString = "umb://media/c33bfe07a82b4df18a79db154139cb91";

// Get the guid from this string.
var imageGuidUdi = GuidUdi.Parse(imageString);

// Get the ID of the node!
var imageNodeId = ApplicationContext.Current.Services.EntityService.GetIdForKey(guidUdi.Guid, (UmbracoObjectTypes)Enum.Parse(typeof(UmbracoObjectTypes), guidUdi.EntityType, true));

// Finally, get the node.
var imageNode = Umbraco.TypedMedia(imageNodeId.Result);

Check out this thread on Our Umbraco which covers this issue.

I used this comment to figure out how to get the ID from the image's guid.


It looks like Umbraco HQ is pushing for people to use the new ModelsBuilder with typed models. I'm not sure if Archetype is supported by the ModelsBuilder which is why there's so much trouble.

I personally use Nested Content on all of my projects as it performs the same functionality but (IMO) is better supported by Umbraco because it uses Document Types to store repeatable content schema. Because of this, it can then easily be mapped to IPublishedContent and therefore is supported by the ModelsBuilder!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!