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
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
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)
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
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
https://docs.umbraco.com/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/block-editor/block-grid-editor#2.-build-your-own-rendering
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!
Regards
Marc
is working on a reply...