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 14 posts 95 karma points c-trib
    Aug 29, 2019 @ 18:51
    Mikael Axel Kleinwort

    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 5440 posts 20363 karma points MVP 3x admin c-trib
    Aug 29, 2019 @ 22:35
    Alex Skrypnyk

    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 -

    Thanks, Alex

  • Mikael Axel Kleinwort 14 posts 95 karma points c-trib
    Aug 30, 2019 @ 19:02
    Mikael Axel Kleinwort

    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: