Copied to clipboard

Flag this post as spam?

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


  • Mikael Kleinwort 8 posts 89 karma points
    16 days ago
    Mikael 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 5329 posts 19591 karma points MVP 3x admin c-trib
    16 days ago
    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 Kleinwort 8 posts 89 karma points
    15 days ago
    Mikael 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

Please Sign in or register to post replies

Write your reply to:

Draft