Override layout paths in Neos Flow with Views.yaml

With Neos Flow you can override a certain option of your view class, depending on one or more values of the current request.

The concept is farily well documented so instead of copy/paste I will provide a ways I’ve used it

Reuse a Layout from a different package

I tend to split some functionality into separate packages, but will love to use template parts from my main application package to avoud duplicates.

In this example, I will show you how my Vendor.Login package will use the Default.html layout from my Vendor.Application package

To do so, I can create a Views.yaml file in my Vendor.Login package and have it contain the following

  requestFilter: 'isPackage("Dafis.Login")'
      'Vendor.Login': 'resource://Vendor.Application/Private/Layouts'

The requestFilter option can use methods from the RequestMatcher class to create conditions. Read the Flow documentation for further details on conditions.

The options key allow to overrode certain options from the implemented template class. If you use Neos Fluid Adaptor and the TYPO3 Fluid rendering engine the TemplateView class will be the default, and you can find possible options to override in the implementation.

Now, when my templates in Vendor.Login contains

<f:layout name="Default" />

Flow will automatically

  1. Find the Views.yaml
  2. Check if the requestFilter matches current request
  3. If it does (in our case with Vendor.Login) look for the Default.html layout file in the Vendor.Application package