Nested blocks - field template setup

Hi,

I have a question regarding nested blocks and how to define the type of blocks that are allowed to be nested.

Assume that we have a situation like the one shown in one of the Litium guides (Blocks) where the footer column block has the footer links block nested. How can I set this up in code so that it’s only possible to have the footer links block type nested in the footer column block?

I’ve tried to set the TypeSelections in the field template setup for the parent block. In order to get the id of the block that is going to be nested I’ve used the FieldTemplateService but this process assumes that the block that is going to be nested (footer links) already exists. Although this might not be the case if both blocks are created at the same time, for example when the application starts for the first time and all the field templates are being created.

I’ve tried to remove and create the templates a couple of times and it has happened that the template for the block that is supposed to be nested is being created after the parent block. In this situation the FieldTemplateService is not able to retrieve the ID of the block to be nested and set the TypeSelections property on the parent block.

I would like to make sure that the blocks are created in the correct order, so that the template for the block type that is supposed to be nested is created before the parent block. Does anyone know how to solve this issue?

Litium version: 8.10.0

How do you define the block templates?

If you define the templates in c# you need somehow to define the order that the template should be created, either if you have them in an array and then it’s the order in the array that making the order they will be created in, if they are defined in different files you need to add like a order-property that all the field templates will be ordered in before they are created.

In Storefront CLI and the definition import command all the field templates are created first without the TypeSelections set, and when all templates exists they will be updated with the correct TypeSelections from the definition.

The TypeSelections should contain the list of block templates that can or cant be created as children, depend on the TypeCombination setting.

Thanks for the reply! The field templates are defined in separate files, inheriting FieldTemplateSetup. As you indicated I was looking for a way to define the order in which they are being created, and I think we managed to solve it based on your suggestion on using an order property.

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