Creating a custom container block ================================= Containers are blocks like any other, so everything described in chapter on creating a custom block applies here. The difference between regular blocks and containers is that containers can contain other blocks. This is achieved by using something called a placeholder, which is nothing more than a label which is applied to every child block in a container. When rendering the container, you can use this label to specify where in the template will all blocks with that label be rendered. As with zones, all blocks with a specified label will be rendered one after another. Think of a placeholder in the container block as a lightweight variant of a zone in a layout. When you drag and drop a new block to a placeholder in a container, placeholder label is automatically assigned to the new block so it can be rendered when requested. .. note:: Currently, it is not possible to add containers within containers. Container definition handler ---------------------------- When creating a custom block definition handler for a container block, in addition to extending from ``Netgen\Layouts\Block\BlockDefinition\BlockDefinitionHandler`` abstract class, you will need to implement ``Netgen\Layouts\Block\BlockDefinition\ContainerDefinitionHandlerInterface``. What is left for you to do is to define which placeholders your new container block has by implementing ``getPlaceholderIdentifiers`` method. For example, ``Two columns`` container block provided by Netgen Layouts looks like this: .. code-block:: php
{{ nglayouts_render_placeholder(block, 'left') }}
{{ nglayouts_render_placeholder(block, 'right') }}
{% endblock %} As for backend Twig templates for container blocks, they are similar to backend Twig templates for layout types. They do not need custom logic to render the blocks, except specific HTML elements used as markers for block placeholders: .. code-block:: twig {% extends '@nglayouts_admin/app/block/block.html.twig' %} {% block content %}
{% endblock %} Basically, for every placeholder in your container block, you need to have a ``
`` element with a placeholder identifier in ``data-placeholder`` attribute.