Copied to clipboard

Flag this post as spam?

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


  • sam how 11 posts 91 karma points
    Apr 25, 2023 @ 03:33
    sam how
    0

    how to render block list inside block list in umbraco

    How to render block list inside block list? For example I have Block List named Link and inside it I also have a Block List named Sub Link. How can I render the Sub Link. The Links are already rendering but I'm having hard time rendering the Sub Links.

  • Dhanesh Kumar MJ 158 posts 511 karma points c-trib
    Apr 25, 2023 @ 06:30
    Dhanesh Kumar MJ
    0

    Helo sam,

    If you want to create navigation like this

    • MainNav1
      • Sub Nav1
      • Sub Nav2
    • MainNav2
      • Sub Nav1
      • Sub Nav2

    Then you can create one blocklist with a property to add sub links like below.

    enter image description here

    Code:

      @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockListItem>
        @{
    
        //get the content model
            var contentModel = Model.Content as ElementHero(elementType);
        //get the settings model
            var settingsModel = Model.Settings as BlockSettings;
    var subNavs=contentModel.SubNavs
    
        <header class="masthead @settingsModel.AdditionalClasses" style="background-image:url('@contentModel.Image.Url()')">
            <div class="container">
                <div class="title text-uppercase">@contentModel.Title</div>
                <a class="btn btn-primary btn-xl text-uppercase js-scroll-trigger" target="@contentModel.CallToActionLink.Target" href="@contentModel.CallToActionLink.Url">@contentModel.CallToActionLink.Name</a>
                <div class="subNav"> 
        @foreach(var subNavItem in subNavs) {
                  <a class="btn btn-primary btn-xl text-uppercase js-scroll-trigger subnavs" target="@subNavItem.Target" href="@subNavItem.Url">@subNavItem.Name</a>
                }
     </div>
     </header> }
    

    Doc here : https://docs.umbraco.com/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/block-editor/block-list-editor

Please Sign in or register to post replies

Write your reply to:

Draft