Copied to clipboard

Flag this post as spam?

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


  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Aug 24, 2016 @ 08:00
    Michaël Vanbrabandt
    0

    How to get the icon of a node using the api

    Hi,

    I have a api which returns the result of following method:

        public IEnumerable<IContent> GetRootNodes()
        {
            return UmbracoContext.Current.Application.Services.ContentService.GetRootContent().OrderBy(c => c.SortOrder);
        }
    

    I get the result as json ( below is of one node in the list ):

    {"Template":{"MasterTemplateId":{"m_boxed":{"m_value":-1}},"Name":"Home","Alias":"Home","Path":"-1,1047","Content":"@inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Home>\r\n@using ContentModels = Umbraco.Web.PublishedContentModels;\r\n@{\r\n\tLayout = null;\r\n}","Id":1047,"Key":"5b8cdc08-ff16-41bf-a38a-fa00b8668307","CreateDate":"2016-08-23T14:37:35.033Z","UpdateDate":"2016-08-23T12:37:35.0474278Z","HasIdentity":true},"Published":true,"ReleaseDate":null,"ExpireDate":null,"WriterId":0,"NodeName":"Home","PublishedState":0,"ParentId":-1,"Name":"Home","SortOrder":0,"Level":1,"Path":"-1,1049","CreatorId":0,"Trashed":false,"Version":"336f2f58-f32f-4559-9946-adfb0bd420a1","ContentTypeId":1048,"Properties":{},"Id":1049,"Key":"7a7e7d4f-b9c0-465f-965d-08dd13b9fd7a","CreateDate":"2016-08-23T14:50:42.447Z","UpdateDate":"2016-08-23T15:45:34.23Z","HasIdentity":true}
    

    But the icon is in the ContentType object. In VS2015 I see this but it does not return this object it only returns the id of the ContentType.

    Do I need to call this in a sepetared function inside my controller or... ?

    /Michaël

  • Nik 1611 posts 7237 karma points MVP 7x c-trib
    Aug 24, 2016 @ 08:07
    Nik
    0

    Hi Michael,

    Firstly, I think I need to ask is your API for front end use or back end use? The reason I ask is that if it is front end you really shouldn't be using the ContentService to retrieve content. This makes calls, as far as I understand it, to the database where as using Umbraco helpers uses the published cache.

    However, in answer to your actual question I believe you would either need to create a custom model to return then you could put all the information in one call, else you will need to make a new call to retrieve the content type for each unique content type you want to know about.

    Thanks,

    Nik

  • Damiaan 442 posts 1302 karma points MVP 6x c-trib
    Aug 24, 2016 @ 08:10
    Damiaan
    0

    What Nik said. If you have only the ContentType id, you can call the contentTypeService to get all information about your content type.

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Aug 24, 2016 @ 08:13
    Michaël Vanbrabandt
    0

    Hi,

    I am building a custom plugin which is a new tab in the content section so its not for the frontend.

    A custom model will be hard I think because I will be using services where the args.node is needed, which is the IContent model or am I wrong?

    /Michaël

  • Nik 1611 posts 7237 karma points MVP 7x c-trib
    Aug 24, 2016 @ 08:20
    Nik
    0

    Hi Michael,

    I think you need to explain a bit more about what you are trying to achieve. What is args.node ? If that is just a property on an object then you can easily create your own model that has said property on it, plus additional properties such as the content type etc.

    Nik

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Aug 24, 2016 @ 08:23
    Michaël Vanbrabandt
    100

    Ok I have solved it like the suggestion of creating a new ViewModel where I put my IContent and IContentType objects.

    Thanks

    /Michaël

  • Ian 178 posts 752 karma points
    Aug 24, 2016 @ 09:08
    Ian
    0

    Im fully with you creating models tailored to your purpose when subsetting or extending information but fpr your purpose does contentresource not do want you want without additional coding? See this https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/53002-How-get-properties-of-current-node-in-custom-propertie-editor the angular resource contains various methods you might be able to call.

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Aug 24, 2016 @ 09:18
    Michaël Vanbrabandt
    0

    Yes it can also but then it will call the database again and if I have 200 nodes to evaluate that will be hard for the database.

    In my api I have already all the intel so I just need to merge it into my viewmodel and sent it back.

    /Michaël

Please Sign in or register to post replies

Write your reply to:

Draft