Using themes

Themes in Netgen Layouts provide a way to quickly override any frontend layout, block and block item templates provided by Netgen Layouts.

Once configured, the override process works based on convention. That is, you only need to place templates at certain paths, and they will automatically be picked up and used instead of the built in templates.


Currently, only frontend templates use themes. Overriding backend templates still works in very much the same way as always.

Netgen Layouts theme support defines two concepts: a design, and a theme, design being a collection of themes and theme being a collection of paths where templates are being loaded from.

When searching for a template, the system looks at the currently configured design and starts looking for the template in all themes within the design, one by one. First path from the first theme which exists for the specified template is used. This makes it possible to override any built in theme by creating a design that contains the original theme and your new theme that only has the overriden templates.

The system also comes with one built in theme called standard, which is always used as a fallback when no templates are found in your custom design/themes. All frontend templates for layouts, blocks and block items are part of this built in theme.

Getting started with themes

To specify which design your frontend will use, you need to add it to configuration and specify the currently used design:

        my_design: [my_theme, my_other_theme]
        my_second_design: [my_theme, my_third_theme]
    design: my_design

With above configuration, we defined two designs, called my_design and my_second_design, with their themes, and we specified that currently used design is my_design.


If you’re using eZ Platform, currently used design can be siteaccess aware, meaning, you can use configuration similar to this to specify different designs for different siteaccesses or siteaccess groups:

            design: my_design
            design: my_second_design


If you only ever intend to use one theme and knowing that standard theme is always available and ready to be used, you don’t need to configure anything, no design, no themes, and you can simply use standard theme for your own templates.

Theme folders

For every theme you defined, system reserves some special folders where you need to place the templates for them to be recognized. The folders are, in descending order of priority:

  • app/Resources/views/ngbm/themes/<THEME NAME>
  • %twig.default_path%/ngbm/themes/<THEME NAME> (for Symfony 3.4+, usually templates/ngbm/themes/<THEME NAME>)
  • <PATH TO BUNDLE>/Resources/views/ngbm/themes/<THEME_NAME>

For folders inside the bundles, the bundles activated later in the kernel class have higher priority.

As an example, if you have a design with two themes, theme1 and theme2, and two bundles active, App\FirstBundle and App\SecondBundle (this one being activated later in the kernel), the system will look in the following folders for templates, in descending order of priority (this includes the fallback to standard theme too and Symfony 3.4+ specific path):

  • app/Resources/views/ngbm/themes/theme1
  • templates/ngbm/themes/theme1
  • src/SecondBundle/Resources/views/ngbm/themes/theme1
  • src/FirstBundle/Resources/views/ngbm/themes/theme1
  • app/Resources/views/ngbm/themes/theme2
  • templates/ngbm/themes/theme2
  • src/SecondBundle/Resources/views/ngbm/themes/theme2
  • src/FirstBundle/Resources/views/ngbm/themes/theme2
  • app/Resources/views/ngbm/themes/standard
  • templates/ngbm/themes/standard
  • src/SecondBundle/Resources/views/ngbm/themes/standard
  • src/FirstBundle/Resources/views/ngbm/themes/standard

Using the theme templates

There are two usecases for using themes:

  • Overriding the templates for existing layouts or blocks
  • Creating templates for custom layouts or blocks

In both cases, using the theme templates is exactly the same. Once you define a design and themes, you can reference the templates with a special Twig namespace called @ngbm, followed by the template path, where template path is anything AFTER the theme name in the template path on filesystem. For example, @ngbm/block/my_block.html.twig will look for the template in the following paths:

  • app/Resources/views/ngbm/themes/theme1/block/my_block.html.twig
  • templates/ngbm/themes/theme1/block/my_block.html.twig
  • src/SecondBundle/Resources/views/ngbm/themes/theme1/block/my_block.html.twig

Overriding the templates for existing layouts or blocks

Overriding the templates for existing layouts and blocks is made really simple by using themes, since you don’t need any configuration to override one of the existing templates (apart from configuring the design and themes, obviously).

Lets take an example of a built in layout with the identifier layout_1. This template is located on disk at vendor/netgen/block-manager-standard/bundle/Resources/views/ngbm/themes/standard/layout/layout_1.html.twig path. As you can see, it’s part of the standard theme, meaning, it can be overriden by your themes, just by placing the new template at the correct path. Any of the following paths would be valid (in no specific order of priority):

  • app/Resources/views/ngbm/themes/theme1/layout/layout_1.html.twig
  • src/FirstBundle/Resources/views/ngbm/themes/theme1/layout/layout_1.html.twig
  • app/Resources/views/ngbm/themes/standard/layout/layout_1.html.twig
  • src/SecondBundle/Resources/views/ngbm/themes/standard/layout/layout_1.html.twig

Creating templates for custom layouts or blocks

Apart from referencing the templates with a new syntax, creating and using templates for custom blocks and layouts does not differ. You still need to create block_view or layout_view configuration to specify which template your block will use. For example, to specify the template for a block with identifier my_block, you would use the following block_view configuration. Notice how we’re referencing the template with our special @ngbm Twig namespace:

                    template: "@ngbm/block/my_block.html.twig"
                        block\definition: my_block
                        block\view_type: my_view_type

The template itself would look like this:

{% extends '@ngbm/block/block.html.twig' %}

{% block content %}
{% endblock %}

As you can see, you can even reference the built in templates with @ngbm Twig namespace in your templates, for extending them, including them and so on.


Not all built in templates can be referenced with @ngbm namespace. Only layout, block (including the base block template) and item templates can be used with @ngbm namespace. Referencing all other templates still works by using @NetgenBlockManager namespace.

After you place your template in one of the paths discussed earlier, your template will automatically be picked up and used for rendering your block.