Copied to clipboard

Flag this post as spam?

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

  • Claushingebjerg 937 posts 2572 karma points
    Oct 27, 2023 @ 09:05

    accessing blockgrid settings

    I need to access some settings on a block grid. I installed the examples, and added a settings doc type to the "two column" layout block. All good.

    I need to access these settings on the absolute top level of the block renderer. (default.cshtml)

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockGridModel>
            if (Model?.Any() != true) { return; }
            var settings = Model.Settings;

    But that gives me an error: 'BlockGridModel' does not contain a definition for 'Settings' and no accessible extension method 'Settings' accepting a first argument of type 'BlockGridModel' could be found (are you missing a using directive or an assembly reference?)

    Whats the syntax for accessing the settings at this level/Model

  • Marc Goodson 2149 posts 14354 karma points MVP 8x c-trib
    Oct 29, 2023 @ 21:33
    Marc Goodson

    Hi Claushingebjerg

    At that level the model is a BlockGridModel which is a collection of BlockGridItems, but it's these individual BlockGridItems that have the Settings properties.

    You can see a bit about the possibilities in the custom rendering section in the block grid docs

    Anyway, you should be able to find your two column layout block with something like...

    var twoColBlock = Model. FirstOrDefault(f=>f.Content. ContentType.Alias == "twoColBlockAlias");

    var twoColSettings = twoColBlock. Settings as TwoColSettingsModel;

    Depending on what your blocks and setting blocks are called!



Please Sign in or register to post replies

Write your reply to: