TYPO3 9.5.3 News Archiv and Route Enhancers

ぐ巨炮叔叔 提交于 2020-01-15 09:46:09

问题


I included the RouteEnhancers for the News Plugin and there working as exspected for News List and News Detail Pages. Now i try to implement the DateMenu Archiv and there i have some Problems.

My config.yaml looks like that.

routeEnhancers:
  PageTypeSuffix:
    type: ForceAppendingSlash
  NewsPlugin:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      - routePath: '/news/{page}'
        _controller: 'News::list'
        _arguments:
          page: '@widget_0/currentPage'
      - routePath: '/{news_title}'
        _controller: 'News::detail'
        _arguments:
          news_title: news
      - routePath: '/archiv/{year}/{month}'
        _controller: 'News::archive'
    defaultController: 'News::list'
    defaults:
      page: '0'
    requirements:
      page: \d+
    aspects:
      news_title:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment

My DateMenu.html looks like this:

<ul>
 <f:for each="{data.single}" key="year" as="months">
   <li>
      <ul>
        <f:for each="{months}" key="month" as="count">
          <li>
            <f:link.action pageUid="{listPid}" arguments="{overwriteDemand:{year: year, month: month}}">{year} {month}</f:link.action>
          </li>
        </f:for>
      </ul>
    </li>
  </f:for>
</ul>

Lists are looking good, but i dont know if there are Urls Cached or something else is Wrong. Will there be a Overview again like in RealUrl so you can see all Cached Urls?


回答1:


yes, the URLs seem to be cached. i needed to flush the Typo3 and PHP Cache in the "Maintenance" module (under "Adminn Tools"):

BUT i think there are mistakes in your routeEnhancers configuration. they are not well documented in the CoreApiReference, but there is a good description in the changelog: https://docs.typo3.org/typo3cms/extensions/core/latest/Changelog/9.5/Feature-86365-RoutingEnhancersAndAspects.html

take a look at the generated URLs of the DateMenu - probabbly someting like:

 http://yoursite.com
 /path/to/newspage/
 ?tx_news_pi1[controller]=News
     &tx_news_pi1[overwriteDemand][year]=2018
     &tx_news_pi1[overwriteDemand][month]=10
     &cHash=361b6057014505217b6186a508418f6f

so the controller is not 'archive' but 'list'. you need to change that in your config.yaml. also i think you need to configure the arguments for this route:

 routePath: '/archive/{year}/{month}'
 _controller: 'News::list'
 _arguments:
   year: overwriteDemand/year
   month: overwriteDemand/month

this should transform/get rid of the two &tx_news_pi1[overwriteDemand] parameters.

next, in order to remove the cHash, take a look at the "aspects:" part at the end of the config.yaml file. you have already defined one for "news_title" - and you have to add two more for the new "year" and "month" arguments. there is a multilingual / localized example in the changelog https://docs.typo3.org/typo3cms/extensions/core/latest/Changelog/9.5/Feature-86365-RoutingEnhancersAndAspects.html#staticvaluemapper

below are my entire config.yaml and DateMenu.html files. my setup is:

  • list and the detail view on two different pages - 14 and 39
  • i don't use pagination on the listview
  • i don't want months in the archiv - just years

rootPageId: 1
base: /
baseVariants: {  }
languages:
  -
    title: Deutsch
    enabled: true
    languageId: '0'
    base: /
    typo3Language: de
    locale: de_CH
    iso-639-1: de
    navigationTitle: De
    hreflang: de
    direction: ''
    flag: global
  -
    title: English
    enabled: true
    languageId: '1'
    base: /en/
    typo3Language: default
    locale: en_US
    iso-639-1: en
    navigationTitle: En
    hreflang: en-US
    direction: ''
    fallbackType: strict
    flag: gb
errorHandling: {  }
routes: {  }

routeEnhancers:
 NewsPlugin:
  type: Extbase
  limitToPages:
    - 14
    - 39 
  extension: News
  plugin: Pi1
  routes:
    -
     routePath: '/{news_title}'
     _controller: 'News::detail'
     _arguments:
       news_title: news
    -
     routePath: '/{year}'
     _controller: 'News::list'
     _arguments:
       year: overwriteDemand/year
  defaultController: 'News::list'
  defaults:
   page: '0'
  aspects:
   news_title:
    type: PersistedAliasMapper
    tableName: tx_news_domain_model_news
    routeFieldName: path_segment
   year:
    type: StaticRangeMapper
    start: '2000'
    end: '2200'

<div class="news-menu-view">
    <ul>
        <f:for each="{data.single}" key="year">
            <li>
                <f:link.action pageUid="{listPid}" arguments="{overwriteDemand:{year: year}}">{year}</f:link.action>
            </li>
        </f:for>
    </ul>
</div>


来源:https://stackoverflow.com/questions/53883367/typo3-9-5-3-news-archiv-and-route-enhancers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!