Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Speaking URLs for News 7.0.7 on Typo3 9.5.0

I really like the ease Typo3 9.5.0 is creating speaking URL's.

The only problem I do have is to make it work with extensions like news. Could not find a way to make it work and have no clue where to start. Appreciate your help.

Best regards Dan

TYPO3 9.5.0 News 7.0.7

like image 422
danriesen Avatar asked Oct 25 '18 07:10

danriesen


2 Answers

You can do this with the routeEnhancers directive in your site configuration YAML file (typically htdocs/config/sites//config.yaml). There is an example in the official documentation, though hidden a little bit:

https://docs.typo3.org/typo3cms/extensions/core/Changelog/9.5/Feature-86365-RoutingEnhancersAndAspects.html

This is a configuration I am actively using:

rootPageId: <site id>
...
routeEnhancers:
 NewsPlugin:
  type: Extbase
  limitToPages:
    - 49 (when your news detail page id is 49)
    - ...
  extension: News
  plugin: Pi1
  routes:
    -
     routePath: '/blog/{page}'
     _controller: 'News::list'
     _arguments:
       page: '@widget_0/currentPage'
    -
     routePath: '/tag/{tag_name}'
     _controller: 'News::list'
     _arguments:
       tag_name: overwriteDemand/tags
    -
     routePath: '/{news_title}'
     _controller: 'News::detail'
     _arguments:
       news_title: news
    -
     routePath: '/archive/{year}/{month}'
     _controller: 'News::archive'
  defaultController: 'News::list'
  defaults:
   page: '0'
  aspects:
   news_title:
    type: PersistedAliasMapper
    tableName: tx_news_domain_model_news
    routeFieldName: path_segment
like image 138
Pavel Leonidov Avatar answered Oct 18 '22 18:10

Pavel Leonidov


Working example typo3 9.5.5 with tx_news 7.1.0 with PersistedPatternMapper:

routeEnhancers:
  NewsPlugin:
    type: Extbase
    limitToPages: [20,23,29,30]
    extension: News
    plugin: Pi1
    routes:
      - { routePath: '{page}',_controller: 'News::list',_arguments: {'page': '@widget_0/currentPage'} }
      - { routePath: '{news_title}',_controller: 'News::detail',_arguments: {'news_title': 'news'} }      
    defaultController: 'News::list'    
    defaults:
      page: '0'
    requirements:
      page: '\d+'
    aspects:      
      news_title:
        type: PersistedPatternMapper
        tableName: 'tx_news_domain_model_news'
        routeFieldPattern: '^(?P<path_segment>.+)-(?P<uid>\d+)$'
        routeFieldResult: '{path_segment}-{uid}'
      page:
        type: StaticRangeMapper
        start: '1'
        end: '200'
like image 29
Han Richer Avatar answered Oct 18 '22 19:10

Han Richer