In Typo3 v9 I have routing installed as described here.
But there is always the path segment of the details page in the url.
Even if i write "news-of-the-month" in field "Speaking URL path segment" the url of the news is www.domain.com/details/news-of-the-month
But I want www.domain.com/news-of-the-month
Is that possible?
This is my config.yaml:
rootPageId: 1
base: /
baseVariants: { }
languages:
-
title: Deutsch
enabled: true
languageId: '0'
base: /
typo3Language: de
locale: de_DE.UTF-8
iso-639-1: de
navigationTitle: ''
hreflang: de-DE
direction: ''
flag: de
errorHandling: { }
routes: { }
routeEnhancers:
NewsPlugin:
type: Extbase
limitToPages:
- 39
- 40
- 41
extension: News
plugin: Pi1
routes:
- { routePath: '/{news_title}', _controller: 'News::detail', _arguments: {'news_title': 'news'} }
defaultController: 'News::detail'
aspects:
news_title:
type: PersistedAliasMapper
tableName: 'tx_news_domain_model_news'
routeFieldName: 'path_segment'
routeValuePrefix: '/'
page:
type: StaticRangeMapper
start: '1'
end: '100'
DateMenu:
type: Extbase
extension: News
plugin: Pi1
routes:
# Pagination:
- routePath: '/page/{page}'
_controller: 'News::list'
_arguments:
page: '#widget_0/currentPage'
requirements:
page: '\d+'
- routePath: '/{news-title}'
_controller: 'News::detail'
_arguments:
news-title: news
# Date year:
- routePath: '/dateFilter/{date-year}'
_controller: 'News::list'
_arguments:
date-month: 'overwriteDemand/month'
date-year: 'overwriteDemand/year'
page: '#widget_0/currentPage'
requirements:
date-year: '\d+'
# Date year + pagination:
- routePath: '/dateFilter/{date-year}/page/{page}'
_controller: 'News::list'
_arguments:
date-year: 'overwriteDemand/year'
page: '#widget_0/currentPage'
requirements:
date-year: '\d+'
page: '\d+'
# Date year/month:
- routePath: '/dateFilter/{date-year}/{date-month}'
_controller: 'News::list'
_arguments:
date-month: 'overwriteDemand/month'
date-year: 'overwriteDemand/year'
page: '#widget_0/currentPage'
requirements:
date-month: '\d+'
date-year: '\d+'
# Date year/month + pagination:
- routePath: '/dateFilter/{date-year}/{date-month}/page/{page}'
_controller: 'News::list'
_arguments:
date-month: 'overwriteDemand/month'
date-year: 'overwriteDemand/year'
page: '#widget_0/currentPage'
requirements:
date-month: '\d+'
date-year: '\d+'
page: '\d+'
defaultController: 'News::list'
defaults:
page: '0'
date-month: ''
date-year: ''
aspects:
news-title:
type: PersistedAliasMapper
tableName: tx_news_domain_model_news
routeFieldName: path_segment
page:
type: StaticRangeMapper
start: '1'
end: '25'
date-month:
type: StaticValueMapper
map:
'01': '01'
'02': '02'
'03': '03'
'04': '04'
'05': '05'
'06': '06'
'07': '07'
'08': '08'
'09': '09'
'10': '10'
'11': '11'
'12': '12'
date-year:
type: StaticRangeMapper
start: '2000'
end: '2030'
You need at least one additional path segment (like "details"), because TYPO3 needs to find the page with your details view plugin, except your details view is on your root page. With a details view on your root page you might only want wo show it (via TypoScript condition), when there's a news selected:
[page["uid"] == 1 && (request.getQueryParams()['tx_news_pi1'])['news'] > 0]
# enable news plugin with detail view
[end]
Related
With the below lines in the config.yaml, I configure the URLs for the news plugin in TYPO3. The URLs for the archive (year/month) look like expected, but don't work. I get an error 404.
/year/2020/07/
/year/2020/08/
and so on
When removing the two parts below the comments # Date year/month: and # Date year/month + pagination: I can see, that the archive links look like this:
/page-0/?tx_news_pi1[overwriteDemand][month]=08&tx_news_pi1[overwriteDemand][year]=2020&cHash=3f6c75083013c748da3870210647975b
/page-0/?tx_news_pi1[overwriteDemand][month]=07&tx_news_pi1[overwriteDemand][year]=2020&cHash=26bf541eb04daffaa9b43c033ea2bb90
and so on
The interestion part is the /page-0/ which shouldn't be there but comes from the paginator. After removing the page: '0' in the defaults section, the pagination isn't working anymore...
Am I missing something in my configuration?
My config.yaml:
base: '/'
baseVariants: { }
errorHandling: { }
languages:
-
title: Deutsch
enabled: true
base: /
typo3Language: de
locale: de_DE.UTF-8
iso-639-1: de
navigationTitle: ''
hreflang: ''
direction: ''
flag: de
languageId: '0'
rootPageId: 1
routeEnhancers:
PageTypeSuffix:
type: PageType
default: /
index: ''
map:
/: 0
#################################
########## News Plugin ##########
#################################
# see https://docs.typo3.org/p/georgringer/news/master/en-us/AdministratorManual/BestPractice/Routing/Index.html#human-readable-dates
NewsConfig:
type: Extbase
extension: News
plugin: Pi1
routes:
# Pagination:
- routePath: '/'
_controller: 'News::list'
- routePath: '/page-{page}'
_controller: 'News::list'
_arguments:
page: '#widget_0/currentPage'
requirements:
page: '\d+'
- routePath: '/{news-title}'
_controller: 'News::detail'
_arguments:
news-title: news
# Date year/month:
- routePath: '/year/{date-year}/{date-month}'
_controller: 'News::list'
_arguments:
date-month: 'overwriteDemand/month'
date-year: 'overwriteDemand/year'
page: '#widget_0/currentPage'
requirements:
date-month: '\d+'
date-year: '\d+'
# Date year/month + pagination:
- routePath: '/year/{date-year}/{date-month}/page-{page}'
_controller: 'News::list'
_arguments:
date-month: 'overwriteDemand/month'
date-year: 'overwriteDemand/year'
page: '#widget_0/currentPage'
requirements:
date-month: '\d+'
date-year: '\d+'
page: '\d+'
defaultController: 'News::list'
defaults:
page: '0'
date-month: ''
date-year: ''
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: '500'
date-month:
type: StaticRangeMapper
start: '1'
end: '12'
date-year:
type: StaticRangeMapper
start: '2000'
end: '2030'
routes: { }
UPDATE
With two different configurations I got it almost to work:
#####################################################
########## News detail page and pagination ##########
#####################################################
NewsGeneral:
type: Extbase
extension: News
plugin: Pi1
routes:
- routePath: '/{news-title}'
_controller: 'News::detail'
_arguments:
news-title: news
- routePath: '/page-{page}'
_controller: 'News::list'
_arguments:
page: '#widget_0/currentPage'
requirements:
page: '\d+'
defaultController: 'News::list'
defaults:
page: '1'
aspects:
news-title:
type: PersistedPatternMapper
tableName: tx_news_domain_model_news
routeFieldPattern: '^(?P<path_segment>.+)-(?P<uid>\d+)$'
routeFieldResult: '{path_segment}-{uid}'
page:
type: IdentifierValueMapper
#########################################
########## News archive config ##########
#########################################
# see https://docs.typo3.org/p/georgringer/news/master/en-us/AdministratorManual/BestPractice/Routing/Index.html#human-readable-dates
NewsArchiveConfig:
type: Extbase
extension: News
plugin: Pi1
limitToPages:
- 19
- 313
routes:
# Date year/month:
- routePath: '/year/{date-year}/{date-month}'
_controller: 'News::list'
_arguments:
date-month: 'overwriteDemand/month'
date-year: 'overwriteDemand/year'
# Date year/month + pagination:
- routePath: '/year/{date-year}/{date-month}/page-{page}'
_controller: 'News::list'
_arguments:
date-month: 'overwriteDemand/month'
date-year: 'overwriteDemand/year'
page: '#widget_0/currentPage'
requirements:
date-year: '\d+'
date-month: '\d+'
page: '\d+'
defaultController: 'News::list'
aspects:
date-month:
type: IdentifierValueMapper
date-year:
type: IdentifierValueMapper
page:
type: IdentifierValueMapper
Credits: The IdentifierValueMapperwas taken from here, thanks to exotec!
One last problem: The pagination on the archive pages.
The normal pagination link (/page-2/) leads to an error 404 and a month pagination (/year/2020/08/page-2/) does no respect the month and the year.
Conclusion:
If both configurations are active (which is the case on the archive page), they are interfering with each other.
Any hint is appreciated!
We have a Typo3 9 server with a number of websites running on it. We also have the news plugin to facilitate the addition of blog posts.
With Typo3 9 the old RealURL system has been depricated in favour of a built in system. This is working for the normal pages but is not working for the news articles.
We have implemented the following YAML confic file which is based off the examples provided by the news plugin and a number of other stack overflow posts. The problem is that while we can confirm that the config is loaded, we get a 404 error:
404 Page not found!
Reason: The requested page does not exist
Current URL: /blog/2020-january/
We then commenced in depth, line by line examinantion of the code to understand what is going wrong. We did manage to render the /blog/2020-january/ page, but it had no content. None of the individual blog pages resolve either.
Are there other configurations that we should look for to enable this functionality? We have had another Typo3 person look at the problem without success.
rootPageId: 156
base: 'https://example.site'
baseVariants: { }
languages:
-
title: English
enabled: true
languageId: '0'
base: /
typo3Language: default
locale: en_AU
iso-639-1: en
navigationTitle: ''
hreflang: ''
direction: ''
flag: au
errorHandling: { }
routes: { }
routeEnhancers:
PageTypeSuffix:
type: PageType
default: '/'
index: '/'
map:
'/': 0
NewsPlugin:
type: Extbase
extension: News
plugin: Pi1
limitToPages:
- 187
- 201
routes:
# Detail view:
- routePath: '/{news_title}'
_controller: 'News::detail'
_arguments: {'news_title': 'news'}
# Categories:
- routePath: '/{category}'
_controller: 'News::list'
_arguments: {'category': 'overwriteDemand/categories'}
# Tags:
- routePath: '/{tag_name}'
_controller: 'News::list'
_arguments: {'tag_name': 'overwriteDemand/tags'}
# Pagination:
- routePath: '/{page}'
_controller: 'News::list'
_arguments: {'page': '#widget_0/currentPage'}
# Archive:
- routePath: '/{localized_archive}/{year}/{month}'
_controller: 'News::archive'
# Date:
- routePath: '/{year}-{month}'
_controller: 'News::list'
_arguments:
year: overwriteDemand/year
month: overwriteDemand/month
defaultController: 'News::list'
defaults:
page: '0'
year: ''
month: ''
requirements:
page: '\d+'
news_title: '^[a-zA-Z0-9].*$'
aspects:
page:
type: StaticRangeMapper
start: '1'
end: '100'
news_title:
type: PersistedPatternMapper
tableName: tx_news_domain_model_news
routeFieldPattern: '^(?P<path_segment>.+)$'
routeFieldResult: '{path_segment}'
category:
type: PersistedAliasMapper
tableName: 'sys_category'
routeFieldName: 'title'
tag_name:
type: PersistedAliasMapper
tableName: 'tx_news_domain_model_tag'
routeFieldName: 'title'
localized_archive:
type: LocaleModifier
default: 'archive'
routeFieldName: 'title'
localeMap:
- languageId: 'de_.*'
value: 'archiv'
- languageId: 'fr_.*'
value: 'archives'
year:
type: StaticRangeMapper
start: '1970'
end: '2099'
month:
type: StaticValueMapper
map:
january: '01'
february: '02'
march: '03'
april: '04'
may: '05'
june: '06'
july: '07'
august: '08'
september: '09'
october: 10
november: 11
december: 12
Please check your code see below code of news_title
routeEnhancers: News: type: Extbase extension: News plugin: Pi1 routes: - routePath: '/{news-title}' _controller: 'News::detail' _arguments: news-title: news aspects: news-title: type: PersistedAliasMapper tableName: tx_news_domain_model_news routeFieldName: path_segment
Remove curly braces from path_segment, remove do it as above or in docs thank you
Please see the official documents https://docs.typo3.org/p/georgringer/news/7.2/en-us/AdministratorManual/BestPractice/Routing/Index.html
After a lot of effort we have success.
Firstly, the final working config:
routeEnhancers:
NewsPlugin:
type: Extbase
extension: News
plugin: Pi1
limitToPages:
- 201
- 187
routes:
-
routePath: '/{news_title}'
_controller: 'News::detail'
_arguments:
news_title: news
-
routePath: '/{category}'
_controller: 'News::list'
_arguments:
category: overwriteDemand/categories
-
routePath: '/{tag_name}'
_controller: 'News::list'
_arguments:
tag_name: overwriteDemand/tags
-
routePath: '/page-{page}'
_controller: 'News::list'
_arguments:
page: '#widget_0/currentPage'
-
routePath: '/{year}/{month}'
_controller: 'News::list'
_arguments:
year: overwriteDemand/year
month: overwriteDemand/month
defaultController: 'News::list'
# defaults:
# page: '0'
# year: ''
# month: ''
requirements:
page: \d+
# news_title: '^[a-zA-Z0-9].*$'
aspects:
page:
type: StaticRangeMapper
start: '1'
end: '100'
news_title:
type: PersistedAliasMapper
tableName: tx_news_domain_model_news
routeFieldName: path_segment
category:
type: PersistedAliasMapper
tableName: sys_category
routeFieldName: title
tag_name:
type: PersistedAliasMapper
tableName: tx_news_domain_model_tag
routeFieldName: title
year:
type: StaticRangeMapper
start: '1970'
end: '2099'
month:
type: StaticRangeMapper
start: '01'
end: '12'
#month:
# type: StaticValueMapper
# map:
# january: '01'
# february: '02'
# march: '03'
# april: '04'
# may: '05'
# june: '06'
# july: '07'
# august: '08'
# september: '09'
# october: 10
# november: 11
# december: 12
The important things:
The pagination path includes the page prefix. There is no ambiguity about what page it is on.
No trailing slashes, additionally, the articles also can't have trailing slashes in the path segment. This can be done in the database and clearing the cache after
No defaults
The different month mapping is due to a requirement to match an existing system
We upgraded from 9.5.15 to 9.5.18. It is not clear if this was required.
In the site package, the default TypoScript template included link.skipControllerAndAction = 1. This needs to be removed to show the friendly urls for the articles in the list view. (See How to properly set url-routing for tx-news in TYPO3 9.5.5?)
Finally, for the date, tag and category filters to work, Disable override demand in List->Plugin->Additional must be unticked.
How to migrate from realurl in TYPO3 9.5 ?
I have a list view where you can filter by category AND year.
Filter by category only and filter by year only works, but I it doesnt work for a combined filter as with realurl before. (first route see below)
my current url is: events?tx_news_pi1[overwriteDemand][categories]=34&tx_news_pi1[overwriteDemand][year]=2019
my desired url: events/2019/categoryname
routeEnhancers:
News:
type: Extbase
extension: News
plugin: Pi1
limitToPages:
# list and detail page
- 6
- 42
routes:
# this doesn't work for events?tx_news_pi1[overwriteDemand][categories]=34&tx_news_pi1[overwriteDemand][year]=2019
# with realurl the path was: events/2019/categoryname
- routePath: '/{date-year}/{category-name}'
_controller: 'News::list'
_arguments:
category-name: overwriteDemand/categories
date-year: overwriteDemand/year
requirements:
date-year: '\d+'
defaultController: 'News::list'
defaults:
date-year: ''
aspects:
date-year:
type: StaticRangeMapper
start: '2000'
end: '2030'
category-name:
type: PersistedAliasMapper
tableName: sys_category
routeFieldName: slug
Precondition
The ext:news list view plugin is on page www.domain.com/news [ID 9] and the detail view on www.domain.com/article [ID 39].
Following the official example (docs.typo3.org)
I tried the "Extbase Plugin Enhancer" example of the feature description, but that caused some problems:
The pagebrowser link to page 2 has a cHash: news/list/2?cHash=123456789
The pagebrowser link from page 2 to page 1 has lots of get-parameters: news?tx_news_pi1%5Baction%5D=list&tx_news_pi1%5Bcontroller%5D=News&cHash=123456789 . Without the routeEnhancer it would just be "news" without any get-parameters.
The link to the detail view has a cHash: article/blog/9?cHash=52e8a4b7c6318cfe0273e7eab374e9ae
The urls have unwanted segments ("list" + "blog")
The acticle url does not contain the news title
One cause for some of this issues might be that the paginator does not specify the controller in its links:
news?tx_news_pi1[#widget_0][currentPage]=2&cHash=123456789
My approach, which already fixes the mentioned problems
I splitted this to two separate routeEnhancers (Extbase + Plugin), removed the segments, "defaultController", "defaults", "requirements" and added "aspects":
routeEnhancers:
NewsDetail:
type: Extbase
limitToPages: [39]
extension: News
plugin: Pi1
routes:
- { routePath: '/{news_title}', _controller: 'News::detail', _arguments: {'news_title': 'news'} }
aspects:
news_title:
type: PersistedAliasMapper
tableName: 'tx_news_domain_model_news'
routeFieldName: 'path_segment'
NewsList:
type: Plugin
limitToPages: [9]
routePath: '/{#widget_0/currentPage}'
namespace: 'tx_news_pi1'
aspects:
'#widget_0/currentPage':
type: StaticRangeMapper
start: '1'
end: '1000'
My concerns regarding this approach:
I'm unsure if it would have an advantage (performance or security) to add some "defaults" and "requirements" and if it really is good practice to split this into two separate routeEnhancers.
It limits the amount of list view pages to a maximum of 1000 (I admit that this is a lot). A higher value will result in an error: Range is larger than 1000 items.
If there's a slash / in the news title (f.e. "Monthly Report
2018/07") the automatically generated path_segment will also contain
a slash ("monthly-report-2018/07") and this leads to the following
error in the list view: Parameter "tx_news_pi1__news" for route
"tx_news_pi1_0" must match "[^/]++" ("monthly-report-2018/07" given)
to generate a corresponding URL.
Here is a copy of the YAML configuration created by Georg Ringer:
site_config.yaml
Version by Georg Ringer
rootPageId: 1
base: 'http://t3-master.vm/'
languages:
-
title: German
enabled: true
languageId: '0'
base: /
typo3Language: de
locale: de
iso-639-1: de
navigationTitle: DE
hreflang: ''
direction: ltr
flag: de
googleAnalyticsReportClientId: xxx
googleAnalyticsReportSiteId: yyyy
-
languageId: '1'
title: English
siteTitle: ''
navigationTitle: English
base: /en/
locale: en
iso-639-1: en
hreflang: en
direction: ''
typo3Language: default
flag: gb
fallbackType: strict
errorHandling: { }
baseVariants: { }
xxxx: "as\r\ndas\"\r\nas"
routes: { }
googleTagManager: ''
logo: ''
googleAnalyticsReportClientId: 778798369619-fl4nav20thdvfv2hag2lntf2cg1o2d79.apps.googleusercontent.com
googleAnalyticsReportSiteId: 'ga:136091502'
routeEnhancers:
NewsPlugin:
type: Extbase
limitToPages:
- 25
extension: News
plugin: Pi1
routes:
-
routePath: '/{news_title}'
_controller: 'News::detail'
_arguments:
news_title: news
-
routePath: '/page/{page}'
_controller: 'News::list'
_arguments:
page: '#widget_0/currentPage'
-
routePath: '/time/{year}-{month}'
_controller: 'News::list'
_arguments:
year: overwriteDemand/year
month: overwriteDemand/month
-
routePath: '/category/{category}'
_controller: 'News::list'
_arguments:
category: overwriteDemand/categories
defaultController: 'News::list'
defaults:
page: '0'
year: ''
month: ''
requirements:
news_title: '^[a-zA-Z0-9].*$'
page: \d+
aspects:
news_title:
type: PersistedAliasMapper
tableName: tx_news_domain_model_news
routeFieldName: path_segment
page:
type: StaticRangeMapper
start: '1'
end: '100'
year:
type: StaticRangeMapper
start: '1970'
end: '2020'
month:
type: StaticValueMapper
map:
january: '01'
february: '02'
march: '03'
april: '04'
may: '05'
june: '06'
july: '07'
august: '08'
september: '09'
october: 10
november: 11
december: 12
category:
type: PersistedPatternMapper
tableName: sys_category
routeFieldPattern: '^(?P<title>.+)-(?P<uid>\d+)$'
routeFieldResult: '{title}-{uid}'
My Version
With the following Changes:
Added a trailing slash, to better match the old RealURL configuration
Additions for multilanguage
Removed ID from detail generation
Removed ID from category generation
Removed /page/ from the pagination example
Removed /time/ from the date example
Changed Year End from '2020' to '2099'
Overall structural improvements.
routeEnhancers:
PageTypeSuffix:
type: PageType
default: '/'
index: '/'
map:
'/': 0
NewsPlugin:
type: Extbase
extension: News
plugin: Pi1
limitToPages: [33,59]
routes:
# Detail view:
- routePath: '/{news_title}'
_controller: 'News::detail'
_arguments: {'news_title': 'news'}
# Categories:
- routePath: '/{category}'
_controller: 'News::list'
_arguments: {'category': 'overwriteDemand/categories'}
# Tags:
- routePath: '/{tag_name}'
_controller: 'News::list'
_arguments: {'tag_name': 'overwriteDemand/tags'}
# Pagination:
- routePath: '/{page}'
_controller: 'News::list'
_arguments: {'page': '#widget_0/currentPage'}
# Archive:
- routePath: '/{localized_archive}/{year}/{month}'
_controller: 'News::archive'
# Date:
- routePath: '/{year}-{month}'
_controller: 'News::list'
_arguments:
year: overwriteDemand/year
month: overwriteDemand/month
defaultController: 'News::list'
defaults:
page: '0'
year: ''
month: ''
requirements:
page: '\d+'
news_title: '^[a-zA-Z0-9].*$'
aspects:
page:
type: StaticRangeMapper
start: '1'
end: '100'
news_title:
type: PersistedPatternMapper
tableName: tx_news_domain_model_news
routeFieldPattern: '^(?P<path_segment>.+)$'
routeFieldResult: '{path_segment}'
category:
type: PersistedAliasMapper
tableName: 'sys_category'
routeFieldName: 'title'
tag_name:
type: PersistedAliasMapper
tableName: 'tx_news_domain_model_tag'
routeFieldName: 'title'
localized_archive:
type: LocaleModifier
default: 'archive'
routeFieldName: 'title'
localeMap:
- languageId: 'de_.*'
value: 'archiv'
- languageId: 'fr_.*'
value: 'archives'
year:
type: StaticRangeMapper
start: '1970'
end: '2099'
month:
type: StaticValueMapper
map:
january: '01'
february: '02'
march: '03'
april: '04'
may: '05'
june: '06'
july: '07'
august: '08'
september: '09'
october: 10
november: 11
december: 12
localeMap:
- locale: 'de_.*'
map:
januar: '01'
februar: '02'
maerz: '03'
april: '04'
mai: '05'
juni: '06'
juli: '07'
august: '08'
september: '09'
oktober: 10
november: 11
dezember: 12
- locale: 'fr_.*'
map:
janvier: '01'
février: '02'
mars: '03'
avril: '04'
mai: '05'
juin: '06'
juillet: '07'
aout: '08'
septembre: '09'
octobre: 10
novembre: 11
décembre: 12
yes, you can have them both in the same routeEnhancer - without the unwanted segments:
routeEnhancers:
NewsPlugin:
type: Extbase
limitToPages:
- 9
- 39
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'
aspects:
news_title:
type: PersistedAliasMapper
tableName: tx_news_domain_model_news
routeFieldName: path_segment
page:
type: StaticRangeMapper
start: '1'
end: '999'
That solved the problem fine (at the bottom): https://forge.typo3.org/issues/86895#note-9
Hello I found the following on a TYPO3 Slack channel as what one person was using. This snip of yaml exists at the /config/my-websitename/config.yaml...
routeEnhancers:
NewsList:
type: Extbase
limitToPages: [2,20,21,22,92]
extension: News
plugin: Pi1
routes:
- routePath: '/p{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+'
news_title: '^[a-zA-Z0-9].*$'
aspects:
page:
type: StaticRangeMapper
start: '1'
end: '100'
news_title:
type: PersistedAliasMapper
tableName: 'tx_news_domain_model_news'
routeFieldName: 'path_segment'
The problem
But I noticed that when I have multiple articles with the same title there's not a unique URL.
The question
How can I add the article uid to the path to make it unique or is that a good idea? I found that it was eluded to in the docs but don't know how to get it working to extend what I have already or if there's a better example someone can give me of how to get unique urls for news?
https://docs.typo3.org/typo3cms/extensions/core/latest/Changelog/9.5/Feature-86365-RoutingEnhancersAndAspects.html#persistedpatternmapper
The answer
routeEnhancers:
NewsPlugin:
type: Extbase
extension: 'News'
plugin: 'Pi1'
routes:
- { routePath: '/{news_title}', _controller: 'News::detail', _arguments: {'news_title': 'news'} }
defaultController: 'News::list'
aspects:
news_title:
type: PersistedPatternMapper
tableName: 'tx_news_domain_model_news'
routeFieldPattern: '^(?P<path_segment>.+)-(?P<uid>\d+)$'
routeFieldResult: '{path_segment}-{uid}'