Copied to clipboard

Flag this post as spam?

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


  • Henrik Vincent 122 posts 616 karma points
    Mar 12, 2019 @ 10:49
    Henrik Vincent
    0

    Getting ContentAtRoot in v8

    Hi guys

    Migrating my site to from v7 > v8

    Having some trouble with the following:

    var kunderSection = Umbraco.TypedContentAtRoot().FirstOrDefault(x => x.DocumentTypeAlias == "kunder");
    

    I cant seem to find any documentation on this (maybe not Googling it right).

    I tried changing Umbraco.TypedContentAtRoot() to Model.Content.Root()

    but it tells my IPublishedContent doesn't contain a difinition for FirstOrDefault, which I haven't been able to find a v8 replacement for.

    Hope you guys can help

    Best

    henrik

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Mar 12, 2019 @ 10:56
    Andy Butland
    1

    Umbraco.ContentAtRoot() I think. I've seen a few consistent changes where methods that were TypedContent* are now just Content*.

    Andy

  • Michael Nielsen 154 posts 811 karma points
    Mar 12, 2019 @ 11:24
    Michael Nielsen
    100

    If you use ModelsBuilder (which you definitely should)

    Umbraco.ContentAtRoot().FirstOrDefault(x => x.ContentType.Alias == Kunder.ModelTypeAlias);
    

    if, for some reason, not

    Umbraco.ContentAtRoot().FirstOrDefault(x => x.ContentType.Alias == "kunder");
    

    For getting the top most ancestor in a template, usually the frontpage, you can do

    Model.Root()
    
  • Henrik Vincent 122 posts 616 karma points
    Mar 12, 2019 @ 14:03
    Henrik Vincent
    0

    Thanks Andy and Michael!

    I went with Michaels suggestion, using the ModelsBuilder, but both answers worked great :)

    Have a great day

    Henrik

Please Sign in or register to post replies

Write your reply to:

Draft