Copied to clipboard

Flag this post as spam?

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


  • Ulf Möllerström 69 posts 246 karma points
    Jun 30, 2022 @ 16:58
    Ulf Möllerström
    0

    Get the Document Type Alias by Type

    enter image description here

    Trying to get the doctype alias based on the generated model's name, but I'm absolutely not sure if this is "the way"... (Among other things, I'm not sure if the lowercase alias as key possibly could generate a duplicate key exception.)

    Any other suggestions?

  • james whittington 18 posts 116 karma points c-trib
    Jun 30, 2022 @ 22:21
    james whittington
    1

    Hi Ulf, perhaps I am misunderstanding what you are trying to do, but if you already have a published content model you should be able to get its content type alise like this:

    //If you have an instance of the content you could get it like this      
     var type = Model.ContentType.Alias;
    
    //or if you don't have an instance and need to know an arbitrary type you can do this
    var type2 =  ContentModels.MyModelType.ModelTypeAlias;
    

    Follow up with more details of how you would want to use your method above if neither of these work for your situation.

  • Ulf Möllerström 69 posts 246 karma points
    Jul 01, 2022 @ 07:32
    Ulf Möllerström
    1

    Hi James,

    Isn't that obvious??? :-)

    I was looking to streamline the creation of several sub types on a parent save event with this method:enter image description here

    CreationHelpers.Create<Controls>("Kontroller", content);
    

    Instead of doing this for 10 (possibly more) sub types

    Services.ContentService.Create(
    "Kontroller",
    content,
    Controls.ModelTypeAlias);
    controls.SetValue(nameof(SystemConstraint.ManualCreateLock), content.Key.ToString());
    Services.ContentService.SaveAndPublish(controls, raiseEvents: false);
    

    But now, I think I'll drop the generic and go with a configuration with a dictionary like { Controls.ModelTypeAlias, "Kontroller" },{ Archive.ModelTypeAlias, "Arkiv" }, {...}, ... easy added to in the future and just run them through.

    This is also a part of updating existing entries.

Please Sign in or register to post replies

Write your reply to:

Draft