Template paths

There exist several ways to declare template root paths and partial root paths. The most relevant ones are described below.

Configuration via service container

Attention

Make sure you have defined EXT:handlebars as dependency in your extension(s). Otherwise, template root paths might not be interpreted correctly.

The easiest way to register your template root paths and partial root paths is by using the Services.yaml file:

# Configuration/Services.yaml

handlebars:
  template:
    template_root_paths:
      10: EXT:my_extension/Resources/Private/Templates
    partial_root_paths:
      10: EXT:my_extension/Resources/Private/Partials

The HandlebarsExtension takes care of all template paths. They will be merged and then added to the service container resulting in the following parameters:

  • %handlebars.template_root_paths%
  • %handlebars.partial_root_paths%

You can reference those parameters in your custom configuration to use the resolved template paths in your services.

The drawback of this configuration is that it is applied to the whole TYPO3 instance since there exists only one service container for the whole system. In case you need different template paths for specific parts of your installation, take a look at the following configuration method that uses TypoScript.

Configuration via TypoScript

A more flexible configuration method is the usage of TypoScript. This way you can override the configuration from the service container (as described above) which allows you to define different template root paths and partial root paths for specific parts of the system.

plugin.tx_handlebars {
  view {
    templateRootPaths {
      20 = EXT:my_other_extension/Resources/Private/Templates
    }
    partialRootPaths {
      20 = EXT:my_other_extension/Resources/Private/Partials
    }
  }
}

Note

Configuration of template paths in multiple extensions

If template paths are defined multiple times (e.g. within various extensions that provide Handlebars templates), the ones with the same numeric key will be overridden by the last defined one.