Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Oct 21, 2020 @ 09:48
    Claushingebjerg
    0

    render block list recursively

    How do i render a block list recursively.

    For example i'm using a block list in my footer, which is want to render on all pages...

    @Html.GetBlockListHtml(Model, "sidefod", fallback: Fallback.ToAncestors)   
    

    Doesn't work

  • Claushingebjerg 939 posts 2574 karma points
    Oct 22, 2020 @ 09:24
    Claushingebjerg
    101

    Do it like this my friend:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        Layout = null;
        var node = Model.AncestorOrSelf();
    }
    
    <div>@Html.GetBlockListHtml(node, "footer") </div>
    

    That should work, but doesnt in my case, so i did:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        Layout = null;
        var rootnode = Model.Root();
    }
    
    <div>@Html.GetBlockListHtml(rootnode, "footer") </div>
    
  • Claushingebjerg 939 posts 2574 karma points
    Oct 22, 2020 @ 09:25
    Claushingebjerg
    1

    Wow, thanks H5YR!

  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    Oct 22, 2020 @ 10:13
    Marc Goodson
    1

    He's very good that @Claushingebjerg - you should buy him a beer if you get the chance!

  • Claushingebjerg 939 posts 2574 karma points
    Oct 22, 2020 @ 11:06
    Claushingebjerg
    0

    I think i will... Today! :)

  • Amir Khan 1287 posts 2744 karma points
    Oct 22, 2020 @ 14:42
    Amir Khan
    0

    Glad you got it working, but can't you just do it like with any other property?

    Html.GetBlockListHtml(node, "footer", recurse:true)
    
  • Claushingebjerg 939 posts 2574 karma points
    Oct 12, 2021 @ 12:15
    Claushingebjerg
    0

    Dont think so:

    "The best overload for 'GetBlockListHtml' does not have a parameter named 'recurse'"

  • Zachary Allen 14 posts 85 karma points
    Sep 21, 2024 @ 22:44
    Zachary Allen
    0

    The solution works if you want to grab a Block List from the root node, or a parent, but doesn't give a full Fallback.ToAncestors functionality.

    A better solution for full recursive block list rendering is to Set the BlocklistModel object recursively, then pass that object into Html.GetBlockListHtml()

    Example

    @{
        var blocks = Model.Value<BlockListModel>("blocks", fallback: Fallback.ToAncestors);
    }
    
    @Html.GetBlockListHtml(blocks)
    
Please Sign in or register to post replies

Write your reply to:

Draft