Copied to clipboard

Flag this post as spam?

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


  • Silvan Egger 28 posts 200 karma points
    Apr 20, 2016 @ 21:38
    Silvan Egger
    0

    DocumentType Name but not DocumentTypeAlias

    Hi together

    I'm trying to get the Document Type Name from my IPublishedContent Object in a Partial View.

    I tried this:

    var documentTypeAlias = person.DocumentTypeAlias;
    

    With this i got the Alias of the Document Type, but i want the Name. I already tried things like this

    var type = ContentTypeService.GetContentType(person.ContentTypeId);
    

    But this doesn't work.

    Can anyone help me?

    Greets, Silvan

  • Silvan Egger 28 posts 200 karma points
    Apr 20, 2016 @ 22:01
    Silvan Egger
    0

    I searched for about some hours now and didn't find anything.

    I do this

    IPublishedContent person = CurrentPage;
    int templateId = person.TemplateId;
    

    So then i have the templateId. But now how can i get the template Name?

    I tried this, but this doesnt work:

    Umbraco.Content(templateId);
    

    Any other suggestions?

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Apr 21, 2016 @ 06:19
    Dennis Adolfi
    2

    Hi Silvan!

    Here is how you can get the DocuemtType Name.

    @inherits UmbracoTemplatePage<IPublishedContent>
    @{
        var documentTypeAlias = CurrentPage.DocumentTypeAlias;
        var documentType = ApplicationContext.Current.Services.ContentTypeService.GetContentType(documentTypeAlias);
    }
    <p>@documentType.Name</p>
    

    Let me know if this helps you!!

    All the best! / Dennis

  • Silvan Egger 28 posts 200 karma points
    May 17, 2016 @ 14:37
    Silvan Egger
    0

    Thats only the DocumentType Alias!

    I need the DocumentType Name

    enter image description here

    With your solution i get "Leader" but I need the "Leiter" Value.

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    May 17, 2016 @ 14:44
    Dennis Adolfi
    101

    Did you try this?

    @inherits UmbracoTemplatePage<IPublishedContent>'
    @{
            var documentTypeAlias = CurrentPage.DocumentTypeAlias; <!-- This is the documenttype alias, it is needed to be able to fetch the contenttype with the ContentTypeService on the next line.
    
            var documentType = ApplicationContext.Current.Services.ContentTypeService.GetContentType(documentTypeAlias); <!-- Fetch the documenttype with the alias.
        }
    
            <p>@documentType.Name</p> <!-- This is the name of the documenttype, in your case 'Leiter'
            <p>@documentType.Alias</p> <!-- This is the alias of the documenttype, in your case 'Leader'
    
  • Silvan Egger 28 posts 200 karma points
    May 23, 2016 @ 11:57
    Silvan Egger
    1

    Oops, Sorry.

    I only tried to show @documentType and didn't add @documentType.Name.

    Your solution now worked! Thank you very much! :D

    I spent too much time for this....

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    May 24, 2016 @ 06:33
    Dennis Adolfi
    0

    That sounds great Silvan! Glad that it worked out for you!! I can understand that you got frustrated after spending too much time with this.

    Best of luck to you with the rest of the site!! Have a great day!

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft