Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Craig 34 posts 270 karma points
    Oct 28, 2015 @ 14:32
    Craig
    0

    Umbraco 7 - Get Page Document Type

    Hi,

    I'm writing a Partial View Macro that lists out data from all pages of a specific document type. I've got the pages back okay but would like to get access to the document type that shapes those pages so that I can write out the names of the properties associated with it. All I've found so far makes reference to the DocumentType service e.g. DocumentType.GetByAlias but I don't see anything in the v7 documentation that makes reference to the DocumentType service. Is there a new way of doing this and if not then what namespace do I need to include to get access to the DocumentType service?

    Thanks.

  • Mark 91 posts -18 karma points
    Oct 28, 2015 @ 15:18
    Mark
    0

    I think you can use DocumentTypeAlias e.g.

    foreach(var node in myNodes)
    {
    var myNodeDocType = node.DocumentTypeAlias;
    }
    

    Or something like that.

  • Craig 34 posts 270 karma points
    Oct 28, 2015 @ 15:55
    Craig
    0

    I think that just returns the name (string) of the Document Type and not the actual Document Type itself which is what I'm after.

    Thanks though.

  • Alessandro Calzavara 32 posts 144 karma points c-trib
    Oct 28, 2015 @ 16:11
  • Mark 91 posts -18 karma points
    Oct 28, 2015 @ 16:35
    Mark
    0

    Hey Craig

    See what you mean. You can get the properties for sure, you can do it via a few methods, will come back to you with an example.

    Thanks

  • Craig 34 posts 270 karma points
    Oct 28, 2015 @ 16:35
    Craig
    2

    Thanks Alessandro, that's exactly what I was looking for. I've now been able to get to the Property Names within a specific Tab by querying:

    var contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
    var contentType = contentTypeService.GetContentType(myNode.DocumentTypeId);
    var propertyList = contentType.CompositionPropertyGroups.ToList()[3].PropertyTypes.ToList();
    

    Awesome!

  • Mark 91 posts -18 karma points
    Oct 28, 2015 @ 16:37
    Mark
    0

    Spot on!

Please Sign in or register to post replies

Write your reply to:

Draft