Copied to clipboard

Flag this post as spam?

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


  • Mikael Axel Kleinwort 69 posts 312 karma points c-trib
    Aug 29, 2019 @ 18:51
    Mikael Axel Kleinwort
    0

    Querying for element type data

    I am rather new to Umbraco and very excited about this well-built cms. Wow.

    I am looking for advice on how to query for the element data types. I found many examples for querying content node data, but it does not work for element types.

    Example: I defined an element data type "car" which can be used in nested control property editors on several pages.

    I have 2 different questions:

    1. On a page MyCars with a nested content control cars which can have items of data type car, how do I query for all car items on that page?
    2. How can I find all car items in any nested content control on any page underneath a specific page (all descendant content nodes), which the least performance hit?

    I would be very grateful for a hint into the right direction.

    Best regards! Mikael

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Aug 29, 2019 @ 22:35
    Alex Skrypnyk
    0

    Hello Mikael

    Welcome to our the friendliest community!

    Rendering a nested content is easy, you need to use something like this:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        var items = Model.Value<IEnumerable<IPublishedElement>>("cars");
    
        foreach(var item in items)
        {
            // Render your content, e.g. item.Value<string>("heading")
        }
    }
    

    docs - https://our.umbraco.com/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Nested-Content/#rendering-nested-content

    Thanks, Alex

  • Mikael Axel Kleinwort 69 posts 312 karma points c-trib
    Aug 30, 2019 @ 19:02
    Mikael Axel Kleinwort
    0

    Hello Alex,

    first let me say that it is amazing how much I can feel and perceive the remarkable friendliness of the Umbraco community, both here in the forum and also elsewhere when I read from and interact with people contributing to Umbraco. In a way, this makes me want to contribute as well, both as a programmer and as a human being, so to speak.

    Thank you for your input. Somehow I missed this part of the docs.

    As far as my second question goes, I am still unclear. I am experimenting and will come back with another followup question (or I will answer my own question, for the benefit of others with the same ignorance :-)

    Best regards! Mikael

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies