Can not get block name from local blocks


I am trying to receive the name of a local block by using this type of code in the controller of a panel that I am building in Backoffice.

blockName = _blockService.Get(blockId)?.Fields?.GetValue<string>(SystemFieldDefinitionConstants.Name, CultureInfo.CurrentUICulture)
I only receive the name of the global blocks like this.

The difference is that the name of the local block is set in Administration.resx files and the name of the global block is set in Backoffice in a field on the template. Is that why the code it does not work?
How do I reach the name of a loca block?

Litium version: [7.6.2]

The name you set in Administration.resx is the name of the block template, like “Slider” or “Products and banners”. If that’s the name you want you need to use the FieldTemplateService to fetch the template from the blocks FieldTemplateSystemId.

var template = _fieldTemplateService.Get<BlockFieldTemplate>(block.FieldTemplateSystemId));
var name = template.Localizations[CultureInfo.CurrentUICulture]?.Name;

Individual names like “My block” is only ever set for global blocks.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.