Copied to clipboard

Flag this post as spam?

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


  • Frank Buchner 22 posts 90 karma points
    Mar 06, 2019 @ 21:57
    Frank Buchner
    2

    DocumentTypeAlias In Umbraco 8

    Hi, I'm trying to convert some old code from v7 to v8. Previously I used CurrentPage.DocumentTypeAlias == "SomeDocType" to compare document type alias in my page which is an UmbracoViewPage. However, when I try Model.DocumentTypeAlias it gives the error:

    'IPublishedContent' does not contain a definition for 'DocumentTypeAlias' and no accessible extension method 'DocumentTypeAlias' accepting a first argument of type 'IPublishedContent' could be found (are you missing a using directive or an assembly reference?)

    What is the proper way of finding a Model's DocumentTypeAlias?

    Thanks!

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Mar 06, 2019 @ 22:30
    Marc Goodson
    110

    Hi Frank

    Have you tried...

    @Model.ContentType.Alias
    

    Essentially IPublishedContent now has an 'IPublishedElement' describing it's ContentType.

    There is additional a new extension method to check whether an IPublishedContent item is a certain type:

    @if(Model.IsDocumentType("someDocTypeAlias")){
    // do somedocTypeAlias specific stuff
    }
    

    regards

    marc

  • Frank Buchner 22 posts 90 karma points
    Mar 07, 2019 @ 15:03
    Frank Buchner
    0

    Thanks! Model.IsDocumentType worked perfectly!

Please Sign in or register to post replies

Write your reply to:

Draft