This project is read-only.

GetItemMetaData Overrides Blog Example? What does it mean?

Topics: Writing themes
Aug 14, 2012 at 2:29 AM

Hi Guys,

I can see that you can override those items in a handler.. I'm just wondering in the blog example.. what do the displayroutevalues settings ACTUALLY do.



Data Manipulation

You can override the following methods to perform actions related to the state of the data:

  • GetItemMetadata
  • BuildDisplayShape
  • BuildEditorShape
  • UpdateEditorShape

For example, the BlogPostPartHandler class overrides the GetItemMetadata method to add route values using code like the following:

protected override void GetItemMetadata(GetContentItemMetadataContext context) {
    var blogPost = context.ContentItem.As<BlogPostPart>();

    if (blogPost == null)

    context.Metadata.CreateRouteValues = new RouteValueDictionary {
        {"Area", "Orchard.Blogs"},
        {"Controller", "BlogPostAdmin"},
        {"Action", "Create"},
        {"blogId", blogPost.BlogPart.Id}
    context.Metadata.EditorRouteValues = new RouteValueDictionary {
        {"Area", "Orchard.Blogs"},
        {"Controller", "BlogPostAdmin"},
        {"Action", "Edit"},
        {"postId", context.ContentItem.Id},
        {"blogId", blogPost.BlogPart.Id}
    context.Metadata.RemoveRouteValues = new RouteValueDictionary {
        {"Area", "Orchard.Blogs"},
        {"Controller", "BlogPostAdmin"},
        {"Action", "Delete"},
        {"postId", context.ContentItem.Id},
        {"blogSlug", blogPost.BlogPart.As<RoutePart>().Slug}

Aug 25, 2012 at 12:28 AM

Certain parts of the CMS will invoke GetItemMetadata and inspect the returned ItemMetadataContext object to setup a link. For example, check out Orchard.Mvc.Html.ContentItemExtensions.ItemDisplayUrl:

public static string ItemDisplayUrl(this UrlHelper urlHelper, IContent content) {
            var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
            if (metadata.DisplayRouteValues == null)
                return null;

            return urlHelper.Action(

As you see, this method depends on the metadata for the specified content to generate a url for displaying the item. By default, the ContensHandler in the Contents module will provide route values for all content items. That's how you're able to view any content item of any content type you specify.

Likewise, the ItemRemoveLink extension method of ContentItemExtensions uses the metadata to setp a remove route. In this case, the BlogPost type needs special handling, which is implemented in the BlogPostAdmin Controller. That's why you see the Blogs module overriding the RemoveRouteValues property.

Pretty cool, don't you think?