Block List and Block Grid Components Folder

In the Umbraco Foundation course it mentions that Block List and Block Grid can share blocks but not how.
Co-Pilot returns:
“In Umbraco 15+, the Block List and Block Grid editors can share blocks, allowing for more flexibility in structuring content. This is an evolution from v13, where blocks were expected to be stored in component folders under Block List and Block Grid.”
Yet in 15+ I still see:

List
@await Html.PartialAsync("blocklist/Components/" + data.ContentType.Alias, block)

Grid
var partialViewName = "blockgrid/Components/" + item.Content.ContentType.Alias;

Do I just change them both to a shared components directory or are these just legacy templates?
Do any of you already have shared blocks and how do you do it?

I think you would struggle with this in a strongly typed set of components because they inherit from different base classes.

Grid items inherit from BlockGridItem and List from BlockListItem. They do share a common parent (IBlockReference) but I don’t see how you could do this because grid items can also have settings.

Is it likely that the course means the elements in the backoffice can be used in both Grid and List?

I think they meant the element type?
But fair point about settings.
I know it has been discussed so maybe we are getting settings for block list items too?

Block List blocks has always had the ability to add settings.

My bad @skttl of course they do.
I think perhaps @rickbutterfield meant settings unique to grid such as Areas.

I think they mean that a block is simply an element type and you can add that element type multiple times to diferent Block Grid Editors and Block List Editors (and to the RTE for that matter)? You would need to configure them multiple times though (for instance the thumbnail or description etc), but the data would be the same.

If you wanted to use the same Element Type in a Block List and a Block Grid you would have to make a corresponding partial view in blockgrid/Components and blocklist/Components though wouldn’t you?
I am interested to see if anyone has a block/Components that works for both.
I may have to try something myself

I know some are reusing partial views for all kinds of blocks, by simply not using the BlockListItem, BlockGridItem etc base class, but instead passes the content part in, and adding settings in a view data dictionary.

Like so

@await Html.PartialAsync("blocks/" + block.Content.ContentType.Alias, block.Content, new ViewDataDictionary(ViewData){ { "settings", block.Settings }})

The individual block views then use

@inherits UmbracoViewPage<ContentModels.MyBlock>
@{
    var settings = ViewData["settings"] as IPublishedElement;
}
1 Like

Thanks @skttl - I am doing that as well for certain types of content.

We have had success with this pattern in the views of block items:

@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<IBlockReference>

@{
    if (Model is null) { return; }

    var component = Model switch
    {
        BlockGridItem gridItem => gridItem.Content as ContentDocTypeModel,
        BlockListItem listItem => listItem.Content as ContentDocTypeModel,
        _ => null
    };

    var settings = Model switch
    {
        BlockGridItem gridItem => gridItem.Settings as SettingsDocTypeModel,
        BlockListItem listItem => listItem.Settings as SettingsDocTypeModel,
        _ => null
    };

    if (component is null || settings is null)
    {
        return;
    }
}

<!-- markup goes here -->
1 Like

That is neat - thank you @eqtr-ab

These are the last discussions I can find and they are about reusable blocks but I think they were also going to merge the block types as well

and