Copied to clipboard

Flag this post as spam?

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


  • Robert Johnston 16 posts 106 karma points
    Jul 18, 2022 @ 23:13
    Robert Johnston
    0

    Is it possible to render a blocklist inside of another block list?

    Good afternoon everyone, I'm trying to see if I can render a nested blocklist inside of another. I am able to this with a blocklist that contains a single type of block. I would like to do this with a blocklist that contains multiple types of blocks.

    For example I'm working on a block that will have two sections a content column for my blocklist and an aside column for a grid editor so I can utilize macros in my aside (sub nav, etc..).

    I'm unable to get the nested blocklist to render at all.

    Any ideas? Thanks in advance.

  • Huw Reddick 1819 posts 6253 karma points MVP 2x c-trib
    Jul 19, 2022 @ 12:45
    Huw Reddick
    0

    Hi,

    Yes, it is possible to do this. IIRC, I created views under Partials\blocklist to do this. I will dig out my code later and see if I can remember what I did.

  • Robert Johnston 16 posts 106 karma points
    Jul 19, 2022 @ 22:08
    Robert Johnston
    0

    Awesome, thank you very much!

  • Robert Johnston 16 posts 106 karma points
    Jul 20, 2022 @ 00:18
    Robert Johnston
    100

    I got it, it's amazing what happens when you use the proper helper. I tried this with the ModelsBuilder helper and got it to work.

    Thank you again!

  • Huw Reddick 1819 posts 6253 karma points MVP 2x c-trib
    Jul 20, 2022 @ 05:28
    Huw Reddick
    0

    Glad you sorted it 🙂

  • Craig100 1136 posts 2523 karma points c-trib
    Jun 13, 2023 @ 14:00
    Craig100
    0

    I don't see the answer here. Any clue would be helpful as I'm trying to nest a BlockList inside a BlockGrid item.

    Thanks.

  • Robert Johnston 16 posts 106 karma points
    Jun 16, 2023 @ 16:48
    Robert Johnston
    0

    Craig100,

    I'll go back and see what I was working on at the time, what version of Umbraco are you using?

  • Craig100 1136 posts 2523 karma points c-trib
    Jun 16, 2023 @ 18:31
    Craig100
    0

    Thanks Robert. It was 10.5.1. I've sorted it out now but it might be useful for others who chance by :)

  • Robert Johnston 16 posts 106 karma points
    Jun 16, 2023 @ 21:58
    Robert Johnston
    0

    So after looking back, this was for a Umbraco 10.1 before the Block Grid Editor which would do this differently.

    My Block (I called it Macro Aside):

    contentBlocks: Used a Block List Editor

    The I had asideContent with a Grid Layout Editor

    enter image description here

    Here is what I used in my view:

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockListItem>;
    @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
    @using Umbraco.Cms.Core.Models;
    @using Umbraco.Cms.Core.Models.Blocks;
    
    @{
        var content = (ContentModels.MacroAside)Model.Content;
        var settings = (ContentModels.MacroSettings)Model.Settings;
        var contain = settings.Value<bool>("inContainer") ? "container-lg" : "container-fluid";
        var blocks = content.ContentBlocks;
    }
    
    <section class="section">
        <div class="@contain">
            <div class="row">
                <div class="col-md-8">
                    @Html.GetBlockListHtml(content.ContentBlocks)
                </div>
                <div class="col-md-4">
                    @Html.GetGridHtml(content, "asideContent", "grid-bootstrap-fluid")
                </div>
            </div>
        </div>
    </section>
    
  • Craig100 1136 posts 2523 karma points c-trib
    Jun 16, 2023 @ 22:22
    Craig100
    0

    Ah, cool.

    Mine turned out to be using the non-ModelsBuilder method when I should have used the ModelsBuilder method!

    I'd used:-

    @Html.GetBlockListHtml(Model.Content.AccordionItems, "accordionItem")

    When it should have just been:-

    @Html.GetBlockListHtml(Model.Content.AccordionItems)

    Anyway, all's well that ends well, as they say ;)

Please Sign in or register to post replies

Write your reply to:

Draft