Copied to clipboard

Flag this post as spam?

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


  • Craig100 1136 posts 2523 karma points c-trib
    Jan 17, 2023 @ 17:24
    Craig100
    0

    Rendering BlockGrid in a partial

    V11.1.0

    The psuedo code below sits in a Partial View that supplies the Main Navigation to a site. What needs to take the place of the ??????? to get it to work? I'd like to add the Model of each item automatically but don't know how.

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<IPublishedContent>
    
    var site = Model.Root();
    var siteSettings = site.Siblings().FirstOrDefault(x => x.ContentType.Alias == "siteWideSettings");
    
    var menuItems = siteSettings.Value<IEnumerable<IPublishedContent>>("megaMenu");
    
    
    foreach (var item in menuItems) {
    
        if (item.ContentType.Alias == "sectionHeader") {       
             @await Html.GetBlockGridHtmlAsync(???????,"subNavLinks")
        }       
    }
    

    Any advice would be appreciated.

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Jan 18, 2023 @ 09:12
    Huw Reddick
    1

    The ??????? needs to be replaced with a BlockGridModel object

    e.g.

    @await Html.GetBlockGridHtmlAsync(item.Value<BlockGridModel>("blogBlock"),"blogBlockTemplate")
    
  • Craig100 1136 posts 2523 karma points c-trib
    Jan 18, 2023 @ 10:42
    Craig100
    0

    Thanks for that but......

    Allowing it to use the default blockGrid template, as all my other blockGrids do, it blows up. So using:-

    @await Html.GetBlockGridHtmlAsync(item.Value<BlockGridModel>("subNavLinks"))
    

    produces:-

    "ModelBindingException: Cannot bind source type Umbraco.Cms.Core.Models.Blocks.BlockGridItem2[[Umbraco.Cms.Web.Common.PublishedModels.Columns66, Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Umbraco.Cms.Core.Models.PublishedContent.IPublishedElement, Umbraco.Core, Version=11.1.0.0, Culture=neutral, PublicKeyToken=null]] to model type Umbraco.Cms.Core.Models.Blocks.BlockGridItem2[[Umbraco.Cms.Web.Common.PublishedModels.Columns66, Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Umbraco.Cms.Web.Common.PublishedModels.BlockSettings, Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]."

    Columns66 being my 2 column layout.

    As the partial is part of a Mega Menu, I was wondering if the blockGrid there is affecting the blockGrid in the main page as well. I mean, can you have more than one blockGrid in a page and can they use the same default template?

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Jan 18, 2023 @ 11:00
    Huw Reddick
    0

    As the partial is part of a Mega Menu, I was wondering if the blockGrid there is affecting the blockGrid in the main page as well. I mean, can you have more than one blockGrid in a page and can they use the same default template?

    I haven't attempted using more than one on a page, but I am using some nested blockgrids on my site so assume you should be able to have more than one blockgrid, I don't know if they can both use the same default template as I use individual templates for most of my blockgrids/items

Please Sign in or register to post replies

Write your reply to:

Draft