Search code examples
yamltypo3-9.x

How to configure the routeEnhancers in Typo3 9?


I'm using typo3 9,5 and I'm trying to generate a route from an extension. Everything is working fine until I found that whenever the URL is much the argument of the route will cause an Error

example:

testRoute:
type: Extbase
extension: testExtension
plugin: testMain
routes:
  - { routePath: '/test/info/{name}/{period}', _controller: 
    'content::info', _arguments: {'name': 'name','period': 'period'} }
defaultController: 'content::info'
aspects:
  # here we get the needed information for a nice URL for _arguments
  name:
    type: PersistedAliasMapper
    tableName: 'xx'
    routeFieldName: slug
  period:
    type: PersistedAliasMapper
    tableName: 'xx'
    routeFieldName: slug

The route is working fine. Problem: if I have any page with period as a name (testperiod) typo3 try to generate testRoute which i defined

   Error
   Parameter "tx_testextension_info__period" for route "tx_testextension_info_0" must 
     match 
    "[^/]++" ("" given) to generate a corresponding URL.

Even if the URL was : /xxxxxxxxxxxxxxxperiod will throw an Error

How can I limit the route for the Extension.


Solution

  • You can try limiting the effect of a route on a specified page using the argument limitToPages. Example :

      NewsList:
        type: Plugin
        limitToPages: [3]
        routePath: '/{@widget_0/currentPage}'
        namespace: 'tx_news_pi1'
        aspects:
          '@widget_0/currentPage':
            type: StaticRangeMapper
            start: '1'
            end: '1000'
    

    In this example, my route will only work on the page 3.