简体   繁体   English

使用TYPO3 9.5.8中的错字为tx_news生成口语URL

[英]Generate speaking url for tx_news using typoscript in TYPO3 9.5.8

I use TYPO3 v 9.5.8 together with tx_news (7.2.0). 我将TYPO3 v 9.5.8与tx_news (7.2.0)一起使用。

I really like the new TYPO3 implemented speaking url generation. 我真的很喜欢新的TYPO3实现的语音网址生成。

I already configured it to generated speaking urls and configurated it to generate speaking urls for tx_news too, both is working fine. 我已经将其配置为生成口语URL,并且也对其进行配置以为tx_news生成口语URL,两者都工作正常。 But I also want to show the last three news entries in page footer. 但我也想在页脚中显示最后三个新闻条目。

My solution was to generate them in typoscript setup and pass them to fluid template. 我的解决方案是在拼写设置中生成它们,并将其传递给流体模板。 My current typoscript code looks like this: 我当前的印刷代码如下:

    news = CONTENT
    news {
        table = tx_news_domain_model_news
        select {
            pidInList = 24
            max = 3
            orderBy = datetime DESC
        }
        renderObj = COA
        renderObj {
            1 = TEXT
            1.field = datetime
            1.strftime = %d. %B %Y
            1.wrap = <p>|</p>

            2 = TEXT
            2 {
                field = title
                typolink {
                    parameter = 26
                    parameter.override.field = internalurl
                    useCacheHash = 0
                    additionalParams.wrap = &tx_news_pi1[news]=|
                    additionalParams.field = uid
                }
            }
        }
        renderObj.wrap = <div class="header-news-item">|</div>
    }

At least this works. 至少这有效。 But since I use additionalParams.wrap to append the id of the news entry, the generated url looks like this: 但自从我使用additionalParams.wrap追加的新闻条目的ID,生成的URL看起来是这样的:

<a href="/allgemeines/news/artikel?tx_news_pi1[news]=2&cHash=8b0067dc86ab1392bb84cbf58878e72d">Lorem ipsum dolor sit</a>

I want to url to look like this: 我想网址看起来像这样:

<a href="/allgemeines/news/artikel/lorem-ipsum-dolor-sit">Lorem ipsum dolor sit</a>

This is the same as tx_news list view generates for redirecting to detail view. 这与为重定向到详细信息视图而生成的tx_news列表视图相同。

Does somebody got an idea how this is possible? 有人知道这怎么可能吗?

我想您在生成TypoScript时缺少动作和控制器。

With the hint from Georg Ringer, I got it working. 在Georg Ringer 的提示下 ,我开始工作了。

Here's the working example, beginning with TypoScript: 这是从TypoScript开始的工作示例:

news = CONTENT
news {
    table = tx_news_domain_model_news
    select {
        pidInList = 24 // Page ID of the page that contains the news entries.
        max = 3
        orderBy = datetime DESC
    }
    renderObj = COA
    renderObj {
        1 = TEXT
        1.field = datetime
        1.strftime = %d. %B %Y
        1.wrap = <p>|</p>
        2 = TEXT
        2 {
            field = title
            typolink {
                parameter = 26 // Page ID of the page that displays the detail view.
                parameter.override.field = internalurl
                useCacheHash = 0
                additionalParams.wrap = &tx_news_pi1[action]=detail&tx_news_pi1[controller]=News&tx_news_pi1[news]=|
                additionalParams.field = uid
            }
        }
    }
    renderObj.wrap = <div class="header-news-item">|</div>
}

To get it working, you have to enable speaking urls for tx_news too, of course. 为了使其正常工作,您当然也必须为tx_news启用口语URL。 You can do this since TYPO3 9 LTS by adding this to the site yaml config file: 从TYPO3 9 LTS开始,您可以通过将其添加到站点yaml配置文件中来执行此操作:

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

This is descripted here . 在这里描述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM