Copied to clipboard

Flag this post as spam?

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

  • John Hodgkinson 613 posts 355 karma points
    Feb 06, 2017 @ 16:34
    John Hodgkinson

    Iterate both content and media

    is there an easy way to iterate both content and media through a collection? I know I can use Umbraco.TypedContentAtRoot() and Umbraco.TypedMediaAtRoot() but is there an easy way to do both through a single call? I would like to iterate through a single collection if possible.

    many thanks!

  • Kevin Jump 2129 posts 13459 karma points MVP 6x c-trib
    Feb 06, 2017 @ 17:26
    Kevin Jump


    from a template i don't think you can get both in one call - content and media are cached in different ways - so there are two caches and you have to do the two calls. :-(

    You can use some of the back office services to get media and content objects in one collection - but you shouldn't do this from your razor templates or any front end code because it will hit the db and be way slower.

    You can however get both elements back using examine - as the search index will have everything in - but this won't give you IPublishedContent elements, as it will give you the search results instead - but it depends on what exactly you need when going through the collections.

  • John Hodgkinson 613 posts 355 karma points
    Feb 10, 2017 @ 12:56
    John Hodgkinson

    Went the Examine route. Thank you for the input.

  • Stefano 61 posts 313 karma points c-trib
    Feb 12, 2017 @ 10:26

    You mean you want to access both media and content in a single collection, together? Otherwise you can probably query the cache for a wildcard XPath!

Please Sign in or register to post replies

Write your reply to: