TYPO3 v10 action controller and template inside subfolders

Viewed 305

Background

Until TYPO3 v9 it was possible to put controllers and fluid templates for the corresponding controller actions into subfolders like this:

Classes/Controller/Product/CarController.php

namespace Vendor\MyExtension\Controller\Product;

class Car extends AbstractProduct {
   public function listAction(){
      // ...
   }
}

ext_localconf.php

ExtensionUtility::configurePlugin(
    'MyExtension',
    'CarsPlugin',
    ['Product\Cars' => 'list'],
    []
);      

Because of the controller name "Product\Cars" the relative fluid template path would be resolved to this:

typo3conf/ext/my_extension/Resources/Private/Templates/Product/Cars/List.html

In TYPO3 v10 this does not work anymore. I guess it's because now your supposed to give a fully qualified controller name like this:

ext_localconf.php

ExtensionUtility::configurePlugin(
    'MyExtension',
    'CarsPlugin',
    [\Vendor\MyExtension\Controller\Product\CarController::class => 'list'],
    []
);

Now, TYPO3 only tries to relove this template: /typo3conf/ext/my_extension/Resources/Private/Templates/Car/List.html

Question

Is there a way for TYPO3 v10 to aknowledge the controller is in a subfolder and resolve the template, also checking the right subfolder?

It makes life that much easier when the file structure is the same. I also think that's especially important when representing complex hierarchies with domain models and controllers inheriting from parent classes, allowing the system to scale (think of Product/Airplane, Product/Ship etc.).

1 Answers

You can add a long list of folders where to search for your layouts/templates/partials. Even in folders from other extensions. Higher key will be tried first

plugin.tx_myextension {
    view {
        templateRootPaths {
             10 = EXT:my_extension/Resources/Private/Templates/
             20 = EXT:my_extension/Resources/Private/Templates/Product/
        }
        partialRootPaths {
            10 = EXT:my_extension/Resources/Private/Partials/
            20 = EXT:my_extension/Resources/Private/Partials/Product/
        }
        layoutRootPaths {
            10 = EXT:my_extension/Resources/Private/Layouts/
            20 = EXT:my_extension/Resources/Private/Layouts/Product/
        }
    }
}
Related